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 above 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 this is being called no matter what the value in evens is. It can be 5 or 3 and still get called. This seems simple enough to me but for some reason is not working as I would expect. 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");
}
Aucun commentaire:
Enregistrer un commentaire