0
How to keep the loop repeating if the user keeps entering a negative number in Java ?
System.out.println("PLease enter number of cake :"); cakeNo = scan.nextInt(); if (cakeNo < 0) { System.out.println("Please enter a positive number of cake :"); // outputs this if the user enters a negative number cakeNo = scan.nextInt(); } else { cakeTime = cakeTime * cakeNo; }
4 ответов
+ 4
If you want a loop, you'll have to use a while instead of an if, and remove the else.
+ 2
if-else statements are conditional statements which offer selection, not loops. They are not capable of looping your program.
+ 1
thanks Hatsy Rei for the information 😃
0
Hatsy Rei that I know but just wanted to know if “if-else” statement could be used or not