I have the user enter a list of 5 ints into an int[]. I then go through those ints in the int[] with a simple for statement. I have an int variable declared called "evens." If the number in the int[] at i %2 == 0 , evens++;
Now I have the if statement:
if (evens !=2 || evens!=3) {
System.out.print("This was called because " + evens + " is not equal to 2 or 3");
}
The problem is that this is being called no matter what the value in evens is. It can be 5 or 3 and still gets called. I've been using C# recently but this is simple Java.
Whole code:
int evens = 0;
for(int i=0; i<chosenNumbers.length; i++) {
if(chosenNumbers[i] %2 ==0)
evens++;
}
System.out.println("You chose "+evens+" even numbers and " + (chosenNumbers.length-evens) + " odd numbers.");
if (evens !=2 || evens!=3) {
System.out.print("This was called because " + evens + " is not equal to 2 or 3");
} else if (evens==2 || evens==3) {
System.out.print(evens +" equals 2 or 3");
}
evens !=2 || evens!=3in English: "if evens differs from 2 or evens differs from 3, then ....". And then you'll realize that any number always differs from 2 or differs from 5. You probably mean and instead of or.