Folow up to first question:
anyone know why this code keeps going in an infinite loop[
^]
This Question:
You will have to make a decision - let the loop run or stop it.
That can be done by a
if/else
. Using the keyword
break
will cause the loop to break and stop.
System.out.println("Enter number");
Scanner input = new Scanner( System.in );
int iDecision = input.nextInt();
if(0 == iDecision){
break;
}
else{
}
EDIT:
I deleted Question number 3 for this homework. Please ask here to keep the information together and our programming suggestions in line - we might confuse you otherwise with contrasting suggestions.
while loop
You can make a while loop that runs infinit:
while(true){
System.out.println("still running");
}
Such a loop needs a break condition. You want the user to decide when that is. So inside the while loop:
- ask User for input
- check input(if/else)
- when user wants to quit "break" the loop.
Have fun.