I have a console application where I need to input numbers until enter "x". Of course when I input "x" i will get a NumberFormatException.
How would I quit the program when entering "x" without getting an exception.
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String s;
int input;
String name = args[0];
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
Date date = new Date();
System.out.println("Good morning " + name + " Today's date is " + sdf.format(date));
System.out.println("Please enter any number between 0 and 10");
try
{
do
{
s = buf.readLine();
input = Integer.parseInt(s);
while(input <= 0 || input > 10)
{
System.out.println("Make sure about the correct input...between 0 and 10 please");
s = buf.readLine();
input = Integer.parseInt(s);
System.out.println(input);
}
}while(s != "x");