-3
int[] usedArray = new int[25];

Random generator = new Random ();

int randomNumber = generator.nextInt(2);

System.out.println(randomNumber);

if(randomNumber != usedArray){
app();
}

while(randomNumber == 0){
score();
question1();
System.out.println(randomNumber);
usedArray[1] = 1;
app();
}

error:'incompatible operand types int & int[]'

How can I say if this number is equal to a number within the array without getting an error?

Leo Rickayzen
  • 43
  • 1
  • 2
  • 6

2 Answers2

1

You are comparing an int with an int[], which is plain wrong. If you want to check if the array contains some integer, then you can do:

if (!Arrays.asList(usedArray).contains(randomNumber)) {
    app();
}
Rohit Jain
  • 209,639
  • 45
  • 409
  • 525
1

You cannot compare a number with an array.

if(randomNumber != usedArray) should be if(randomNumber != usedArray[i]) with i as the index.

hazer_drum
  • 253
  • 3
  • 11