I am new to Java and am having trouble with this particular for loop. Everytime I run the loop and enter a number that is not 1 or 2, the loop displays: "Please choose a correct option". What could be the cause of this?
public class Kbin {
public static void main (String args[]) throws java.io.IOException {
int option;
int i = 0;
System.out.println("What would you like help with?");
System.out.println("\t1. If statement");
System.out.println("\t2. Switch statement");
option = (char) System.in.read();
// loop:
for(i = 0; option != 1 & option != 2; i ++){
System.out.println("What would you like help with?");
System.out.println("\t1. If statement");
System.out.println("\t2. Switch statement");
option = (char) System.in.read();
switch(option){
case '1':
System.out.println("here is how you do an if statement");
i += 1;
break loop;
case '2':
System.out.println("Here is how you do a switch statement");
i += 1;
break loop;
default:
System.out.println("Please choose a correct option.");
continue;
}
}
}
}