Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Mada Akhtar   on May 10 In Java Category.

  
Question Answered By: Maria Miller   on May 10

Try This,
Though I have not tested it Should Probably work

try{
int choice  ;
do {
System.out.println("Help on:");
System.out.println("\t1. if");
System.out.println("\t2. switch");
System.out.println("\t3. while");
System.out.println("\t4. do-while");
System.out.println("\t5. for\n");
System.out.println("Choose one: ");
//choice = (char) System.in.read();
BufferedReader input  = new BufferedReader(new
InputStreamReader(System.in));
String str = input.readLine();

try{
choice = Integer.parseInt(str);
}catch(NumberFormatException e){
choice = 0 ;
}

} while (choice < 1 || choice > 5);

}catch(Exception e){
e.printStackTrace();
}

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Problem with System.in.Read() Or get search suggestion and latest updates.


Tagged: