Reputation: 21
i'm doing an easy exercise for school, everything work except for this method. i want to insert some teams in a vector, but the array "serie" can only be A or B, upper or lower. I check with the debug and the while condition doens't work even if serie[i]=a.
public static void popolamento(String squadre[], char serie[], int punti[]) {
Scanner in= new Scanner(System.in);
for (int i=0;i<punti.length;i++) {
System.out.println("How many teams?");
squadre[i]=in.next();
do {
serie[i]=in.next().charAt(0);
System.out.println(serie[i]);
}
while (serie[i]!='a' || serie[i]!='A' || serie[i]!='b' || serie[i]!='B');
punti[i]=in.nextInt();
}
System.out.println("teams entered correctly ");}
Upvotes: 0
Views: 66
Reputation: 109613
The condition
(X != a || X != b || X != c || X != d)
should have been
(X != a && X != b && X != c && X != d)
Such a pattern is very likely an error, as to fail, all terms must fail When X == u (X != u fails) then X != v holds (different cases assumed), hence always true.
If you read something like this, you know it is in 99.9% an error.
Upvotes: 1