posted 11 years ago
I wrote a simple program where a user is asked for his name , his preferred discount rate and also the cost of his bill. The discount is calculated and the end statement shows all the above variables. The code is written inside a while loop so that the user can repeat the same operation even after the first result.
The code is given below:
The above program works fine. But if give the scanner object creation outside the while loop , then when i go for the second attempt , the cursor does not go for line 15 i.e the name is not accepted and it goes to line 17. Why doesnt the compiler work for the name part if the scanner is declared outside the while loop?Thanks in advance