The operator || is undefined for the argument type(s) boolean, int

boolean-logic, if-statement, java

Solution

month == 1 || 2 || 3

first part of expression would return `boolean` and you cannot `||` `boolean` and `int`

change it to

if( month == 1 || month == 2 || month == 3 )

or

if( month >= 1 &&  month <= 3 )

considering `month` is `int`

Problem

I have little problem with my Java code. I am using Dr.Java and it is giving me the error message that "The operator || is undefined for the argument type(s) boolean, int". If anyone could please ``` import java.util. Scanner; public class Days { public static void main( String [] args) { Scanner in = new Scanner(System.in) ; System.out.print(" What month is it ? " ); int month= in.nextInt(); System.out.print( " What day is it " ); int day = in.nextInt( ); **if( month == 1 || 2 || 3 )** { System.out.print( " Winter" ) ; } else { System.out.print( " Fall " ) ; } } } ```

Original source

Related problems