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

34,696

Solution 1

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

Solution 2

Your syntax is wrong. Correct syntax is

if( month == 1 || month == 2 || month ==3 ) { .... }
Share:
34,696
user3294305
Author by

user3294305

Updated on May 26, 2021

Comments

  • user3294305
    user3294305 almost 3 years

    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 " ) ;
        }
    
    
    }
    }