我的if语句无法正常工作。目的是将用户给定日期与当前日期进行比较,如果月份和周数都匹配(用户的生日),则getBonus = true。 但是,我的if语句给了我以下错误:
二元运算符'&&'的错误操作数类型 第一种类型:int 第二种类型:int
不兼容的类型:int无法转换为boolean
当所涉及的所有变量都是int时,为什么我的if语句试图作为布尔运行?
public static boolean getBonus ( int Week, int Month, int bMonth, int bWeek
) {
boolean getBonus = false;
/**************************************************************************
The following statement is used to determine if the user's birthday is
this week, using the month and week of the month. bMonth/bWeek are generated
from user input, Month/Week are generated from a real time calendar.
**************************************************************************/
if(bWeek = Week && bMonth = Month)
{
getBonus = true;
}
return getBonus;
}//end class getBonus
答案 0 :(得分:0)
这样做
if(bWeek == Week && bMonth == Month)//used to compare
// true && true --> true
而不是这个
if(bWeek = Week && bMonth = Month)//used to assign
答案 1 :(得分:0)
使用If Statement如下
if(bWeek == Week && bMonth == Month)
{
getBonus = true;
}
==用于比较
=用于分配值