Assignment of blank value of input variable after the first loop iteration
Hello!
I am writing a java program, which should display a menu and do some little things as per the options selected.
I want to iterate through the menu till the user presses an invalid input or takes the Quit option.
The problem is once the loop goes good. On second iteration, it shows the menu but does not let the user enter his choice. Byitself, it assigns to blank(' ') and makes the loop terminate(because of invalid entry) after the first iteration.
char input;
do {
System.out.println("Select one of the following :");
System.out.println("[D]");
System.out.println("[E]");
System.out.println("[F]");
System.out.println("[Q]");
input = (char)System.in.read();
if (input == 'd')
{
System.out.println("Thats D");
}
else if (input == 'e')
{
System.out.println("Thats E");
}
else if (input == 'f')
{
System.out.println("Thats F");
}
else if (input == 'q')
{
System.out.println("Quitting...");
// System.exit(0);
}
else
{
System.out.println("Invalid Input");
// System.exit(1);
}
Runtime r = Runtime.getRuntime();
r.gc();
}
while (input == 'd' || input == 'e' || input == 'f');
}
}