[英]error: bad operand types for binary operator '&&' first type int and second type boolean
I am new to java and I really enjoy this new learning experience.我是 java 的新手,我非常喜欢这种新的学习体验。 I got assigned a task where we have to create a simple calendar where the user needs to put a date and the program needs to tell you if it is a correct date.
我被分配了一项任务,我们必须创建一个简单的日历,用户需要在其中输入日期,程序需要告诉您日期是否正确。
However, I receive an error code that I'm using a bad operand type.但是,我收到错误代码,指出我使用了错误的操作数类型。 I cant use an int with a boolean type.
我不能使用 boolean 类型的 int。 However, I do not seem to be able to find the problem.
但是,我似乎无法找到问题所在。
All help and insight is very welcome非常欢迎所有帮助和见解
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");
}
}
You must use if ( (day >= 1 && day <= 31) && (month >= 1 && month <= 12) && (year >= 0))
Also, for every month you need to put month == 2 || month == 4...
您必须使用
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.