0

質問は私のif文についてです。すべて同じ型の 3 つの値を比較していますが、「引数の型 == は boolean,int 型では定義されていません」というようなエラーが発生します && を使用して値を個別に比較するようにコードを変更すると、 .. 値 == 値 1 && 値 = 値 2 なので、エラーは発生しません。違いはなんですか?

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;
            }
        }
    }
4

3 に答える 3

2

あなたのコードは、愚か者としてここを変更する必要があります:

if(cardsIn[index].getValue() == cardsIn[indexCheck].getValue() &&  cardsIn[index].getValue()  == cardsIn[indexCheckThree].getValue())

これで動作するはずです

于 2013-11-10T18:38:36.643 に答える
2

==同じ型の 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
于 2013-11-10T18:38:56.020 に答える
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)そのブール値を整数値と比較して、このエラーが発生する理由を再度比較します

于 2013-11-10T18:43:23.087 に答える