do
{
// asking user choices
choice = Integer.parseInt(br.readLine());
switch(choice)
{
// doing something
}
System.out.println("Do you want to continue?");
System.out.println("(Y/N)");
ans = (char) br.read();
}
while(ans == 'y' || ans == 'Y');
I am using eclipse; I want to check whether the user want to re-enter the switch case by entering his answer by a char 'y' || 'Y'. But whenever i enter the char 'Y' it enters the do loop but also executes the choice variable. And as the choice variable is int; it throws number format exception.
Do you want to continue?
(Y/N)
y
// prints all my switch options
Exception in thread "main":
java.lang.NumberFormatException: For input string: ""
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at ArithemeticOperations.main(ArithemeticOperations.java:45)