I am very new at java and just trying to learn it on my spare time and I'm doing do-while loops and I am having trouble understanding the below code if somebody could help me out that would be great.
public class help {
public static void main (String args[])
throws java.io.IOException {
char choice, ignore;
do{
System.out.println ("Choose one:");
System.out.println("1. if");
System.out.println("2.switch");
choice = (char) System.in.read();
do{
ignore = (char) System.in.read();
}while(ignore != '\n');
}while (choice < '1'| choice >'2');
switch(choice){
case '1':
System.out.println("if");
break;
case '2':
System.out.println("switch");
break;
}
}
}
Whats the point of the block?
do{
ignore = (char) System.in.read();
}while(ignore != '\n');
It makes no difference in the program wither i delete this block or keep it
Also can somebody explain how while (choice < '1'| choice >'2'); translates? I would assume it would be while (choice >= '1'| choice =<'2');?