2014-07-14 5 views
1

J'ai un petit problème avec mon code Java. J'utilise Dr.Java et il me donne le message d'erreur que "L'opérateur || est indéfini pour l'argument type (s) booléen, int". Si quelqu'un pouvait svpL'opérateur || est indéfini pour l'argument type (s) booléen, int

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


} 
} 
+1

La façon dont vous l'avez écrit est syntaxiquement incorrecte. Voir SURESH ATTA pour l'exactitude – Fallenreaper

+0

https://stackoverflow.com/questions/21369530/the-operator-is-undefined-for-the-argument-types-int-int?rq=1 – Ryan

Répondre

1
month == 1 || 2 || 3 

première partie de l'expression retournerait boolean et vous ne pouvez pas ||boolean et int

changement à

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

ou

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

étant donné month est int

9

Votre syntaxe est erronée. La syntaxe correcte est

if(month == 1 || month == 2 || month ==3) { .... } 
Questions connexes