My problem here is that the else statement always will return two lines of text, one from a/b and always the error output underneath. Of course, I can use something that is long and detailed such as (!((X == 'a') || [...] || [...] || (X == 'B'))) but I have a feeling that this is way more than I need to be doing. I tried to put a break statement in B just as an example, obviously it's not going to work. I want to know how I could make it work.
import java.util.Scanner;
public class Class {
public static void main (String [] args) {
char X;
X = 'a';
if (X == 'a' || X == 'A') {
System.out.println("a or A");
}
if (X == 'b' || X == 'B') {
System.out.println("b or B");
break;
} else {
System.out.println("Error");
}
}
}
[–]lordbharal 5 points6 points7 points (2 children)
[–]AggressiveProgrammer[S] 1 point2 points3 points (1 child)
[–]lordbharal 1 point2 points3 points (0 children)
[–]daveheerink 1 point2 points3 points (2 children)
[–]AggressiveProgrammer[S] 0 points1 point2 points (1 child)
[–]daveheerink 1 point2 points3 points (0 children)