While Loop Example
import java.util.Scanner;
class WhileLoop {
public static void main(String[] args) {
int n;
Scanner input = new Scanner(System.in);
System.out.println("Input an integer");
while ((n = input.nextInt()) != 0) {
System.out.println("You entered " + n);
System.out.println("Input an integer");
}
System.out.println("Out of loop");
}
}
Input an integer
7
You entered 7
Input an integer
-2
You entered -2
Input an integer
9546
You entered 9546
Input an inte
ger 0
Out of loop
No comments:
Post a Comment