I am trying the following switch
statements using System.in.read()
:
char ch1, ch2;
ch1 = (char) System.in.read();
switch(ch1) {
case 'A':
System.out.println("This A is part of outer switch.");
ch2 = (char) System.in.read();
// ch2 = 'A';
switch(ch2) {
case 'A':
System.out.println("This A is part of inner switch");
break;
case 'B':
System.out.println("This B is part of inner switch");
break;
} // end of inner switch
break;
case 'B': // ...
ch2 = (char) System.in.read();
not seems to be executed, and unless explicitly state ch2 = 'A'
, the inner switch
statements will not be executed. So how to make the second read()
work?