lundi 26 novembre 2018

Receiving an operator error while creating an If-statement in Java [duplicate]

This question already has an answer here:

While creating an If-statement in Android Studio, I received an error that stated:

Operator '==' cannot be applied to 'int', 'int[]'

The If-statement was supposed to find if one of the numbers that the user inputted was inside the array, and if it did it would display a message.

But while I was doing that, the error appeared in this line: if (n == correctNumbers) {.

Here is my code:

final int[] correctNumbers = {(1),(2),(3),(4),(5)};


public void startGame(View v) {
    int n = Integer.parseInt(Inputs1.getText().toString());

    if (n == correctNumbers) {

        Outputs1.setText("You typed in: " + text + ", which is correct!");

    }


}

Aucun commentaire:

Enregistrer un commentaire