问题是我的if声明。我正在比较所有相同类型的三个值,但我得到一个错误,像这样“参数类型==未定义类型boolean,int”事情是,如果我更改我的代码以使用&amp分别比较值;& .. so value == value1&& value = value2,我没有收到错误。有什么区别?
Card[] cardsIn = cards;
boolean threeOfAKindEval = false;
//the for loops runs through every possible combination of the 5 card array. It starts at
//0,0,0 and ends at 5,5,5/ Inside the last for loop, I check for a three of a kind
//My if statement also checks to make sure I am not comparing the same card with
//itself three times
for(int index = 0; index < cards.length; index++){
for(int indexCheck = 0; indexCheck < cards.length;indexCheck++){
for(int indexCheckThree = 0; indexCheckThree < cards.length;
indexCheckThree++){
if(cardsIn[index].getValue() == cardsIn[indexCheck].getValue() == cardsIn[indexCheckThree].getValue())
threeOfAKindEval = true;
}
}
}
答案 0 :(得分:2)
您的代码需要在此处修改为傻瓜:
if(cardsIn[index].getValue() == cardsIn[indexCheck].getValue() && cardsIn[index].getValue() == cardsIn[indexCheckThree].getValue())
现在它应该工作
答案 1 :(得分:2)
==
比较两个相同类型的参数并返回一个布尔结果。
cardsIn[index].getValue() == cardsIn[indexCheck].getValue() == cardsIn[indexCheckThree].getValue())
评估为
bool temporalBool = cardsIn[indexCheck].getValue() == cardsIn[indexCheckThree].getValue())
bool finalBool = cardsIn[indexCheck].getValue() == temporalBool // <-- left side int, right side bool
&&
运算符执行布尔类型的逻辑AND,因此它就是您所需要的。
cardsIn[index].getValue() == cardsIn[indexCheck].getValue() && cardsIn[index].getValue() == cardsIn[indexCheckThree].getValue()
评估为
bool temporalBool1 = cardsIn[index].getValue() == cardsIn[indexCheckThree].getValue()
bool temporalBool2 = cardsIn[index].getValue() == cardsIn[indexCheck].getValue()
bool result = temporalBool1 && temporalBool2
答案 2 :(得分:0)
您的代码需要在此处修改为傻瓜:
if(cardsIn[index].getValue() == cardsIn[indexCheck].getValue() && cardsIn[index].getValue() == cardsIn[indexCheckThree].getValue())
现在它应该工作
代码
if(cardsIn[index].getValue() == cardsIn[indexCheck].getValue() == cardsIn[indexCheckThree].getValue())
首先比较返回一个布尔值(true/false)
并再次将该布尔值与一个整数值进行比较,以表明您收到此错误的原因