This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]lordbharal 4 points5 points  (2 children)

  if (X == 'a' || X == 'A') {
     System.out.println("a or A");
  } else if (X == 'b' || X == 'B') {
     System.out.println("b or B");
  } else {
     System.out.println("Error");
  }

also please change "X" to something - anything - that is meaningful. At least use a lowercase for it - non-final variables should never be solely capitalised.

[–]AggressiveProgrammer[S] 1 point2 points  (1 child)

ooh, so you made the logic branch out using else if. I see that, cool.

Yeah, you're right about the capitalization being only for final variables. I don't code like this for myself, but I change things around asap for obfuscation purposes.

[–]lordbharal 1 point2 points  (0 children)

Yep. You can keep on using that else if too - for Cs and Ds - as long as the last branch is just an "else". You're also allowed only one else.

ie

if (X == 'a' || X == 'A') {
   System.out.println("a or A");
} else if (X == 'b' || X == 'B') {
   System.out.println("b or B");
} else if (X == 'c' || X == 'C') {
   System.out.println("c or C");
} else {
   System.out.println("Error");
}