繁体   English   中英

错误:二元运算符 '&&' 第一种类型 int 和第二种类型 boolean 的错误操作数类型

[英]error: bad operand types for binary operator '&&' first type int and second type boolean

我是 java 的新手,我非常喜欢这种新的学习体验。 我被分配了一项任务,我们必须创建一个简单的日历,用户需要在其中输入日期,程序需要告诉您日期是否正确。

但是,我收到错误代码,指出我使用了错误的操作数类型。 我不能使用 boolean 类型的 int。 但是,我似乎无法找到问题所在。

非常欢迎所有帮助和见解

public static void main(String[] args) {
    
    Scanner userInput = new Scanner(System.in);  // Creating the new Scanner
    
    System.out.print("Choose a day: ");            //Asking for user to introduce a day
    int day = userInput.nextInt();
    
    System.out.print("Choose a month: ");           // Asking user to introduce a month
    int month  = userInput.nextInt(); 
    
    System.out.print("Choose a year: ");            //Asking user to introduce a year
    int year  = userInput.nextInt(); 
    
    
    if ( (1<= day <= 31) && (1 <= month <= 12) && (year >= 0)){     //marking the limits of day, month and year
        System.out.println(" Congratulations, the date you introduced : " + day + month + year +"exists!!");
    } else if ( (day > 30) && (month = 2 || 4 || 6 || 9 || 10) && (year >= 0)){             //marking the months which have 30 days
        System.out.println(" Oh no, the date you introduced : " + day + month + year +" does Not exists!! You can always try again");
    }else if ( (day > 28) && (month = 2) && (year >=0)){                //marking month February
       System.out.println(" Oh no, the date you introduced : " + day + month + year +" does Not exists!! You can always try again");
    } else {
        System.out.println(" Oh no, the date you introduced : " + day + month + year +" does Not exists!! You can always try again");
    }

}

您必须使用if ( (day >= 1 && day <= 31) && (month >= 1 && month <= 12) && (year >= 0))此外,对于每个月,您需要将month == 2 || month == 4... month == 2 || month == 4...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM