简体   繁体   English

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

[英]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.

相关问题 为什么我会收到此错误? “二元运算符“&amp;&amp;”的操作数类型错误 第一种类型:int 第二种类型:布尔值 - Why am I getting this error? "Bad operand type for binary operator "&&" first type: int second type: boolean" 如何修复错误“二元运算符 &#39;&gt;=&#39; 第一种类型的错误操作数类型:int[] 第二种类型 int” - How to fix the error "Bad Operand Types for Binary Operator '>=' first type: int[] second type int" 获取二元运算符&#39;&gt;&#39;的错误错误操作数类型第一种类型:double []第二种类型:int - Getting error bad operand types for binary operator '>' first type: double [] second type: int 二元运算符&#39;|的操作数类型错误 |” 第一种类型:int; 第二种类型:int。 这是什么意思? - Bad operand types for binary operator '| |' first type: int; second type: int. What does this mean? 二元运算符“&amp;”的错误操作数类型第一种类型:int[] 第二种类型:int - Bad operand types for binary operator ‘&’ First type: int[] Second type: int 二元运算符“!=”的错误操作数类型 第一个类型 int[] 第二个类型 int - Bad operand types for binary operator “!=” first type int[] second type int 二进制运算符“-”的错误操作数类型第一类型:int; 第二种类型:java.lang.String - bad operand types for binary operator “-” first type: int; second type: java.lang.String 二进制运算符&#39;/&#39;的错误操作数类型第一类型字符串第二类型int - Bad Operand types for binary operator '/' first type String second type int 二进制运算符&#39;!=&#39;的错误操作数类型第一类型:字符串第二类型:int - bad operand types for binary operator '!=' first type: String second type: int 错误:二元运算符'.='的错误操作数类型 if(Current_value:= ":"){ ^ 第一种类型:char 第二种类型:String - error: bad operand types for binary operator '!=' if(Current_value != "."){ ^ first type: char second type: String
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM