2014-07-14 57 views
1

我的Java代碼沒有問題。我正在使用Dr.Java,它給了我錯誤消息「The operator ||未定義爲參數類型(s)boolean,int」。如果有人可以請運算符||是未定義的參數類型(s)boolean,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

你寫它的方式在語法上是不正確的。請參閱SURESH ATTA的正確性 – Fallenreaper

+0

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

回答

1
month == 1 || 2 || 3 

表達的第一部分將返回boolean,你不能||booleanint

改變它

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

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

考慮monthint

9

你的語法錯了。正確的語法是

if(month == 1 || month == 2 || month ==3) { .... } 
相關問題