Switch statement:
- Code: Select all
switch( choice = (char)System.in.read());
Here is the full code of my program ( that is not finished yet )
- Code: Select all
/**
*
* @author Administrator
*/
import java.io.*;
public class Test {
public static void main(String[] args)throws IOException{
char choice;
System.out.println("Pick one of the following");
System.out.println("A for Apple");
System.out.println("B for Bapple");
System.out.println("C for Capple");
System.out.flush();
try{
switch( choice = (char)System.in.read());
{
case 'A': System.out.println("You have picked Apple");
break;
case 'B': System.out.println("You have picked Bapple");
break;
case 'C': System.out.println("You have picked Capple");
break;
catch(IOException){
System.out.println("An IO exception has been called");
}
}
}
}
}