006-003-002
While Loop: Input Until Zero
Easy
Problem Description
while loop: Input Until Zero
In this problem, you will create a program that repeatedly reads integers, displays each value as it is entered, and terminates when 0 is input.
Learning Objective: Repeat while condition met with while loop
Create a program that repeatedly reads numbers and terminates when 0 is entered. Use a while loop to repeat while the input value is not 0.
Input
Multiple lines: Numbers (integer, last is 0)
Output
Input: [num1]
Input: [num2]
...
Input: 0
Terminated
Examples
Example 1: Two values then 0
Input:
5
10
0
Output:
Input: 5
Input: 10
Input: 0
Terminated
Example 2: 0 from start
Input:
0
Output:
Input: 0
Terminated
Example 3: Multiple values then 0
Input:
1
2
3
0
Output:
Input: 1
Input: 2
Input: 3
Input: 0
Terminated
Test Cases
※ Output examples follow programming industry standards
Normal case
Input:
7 0
Expected Output:
Input: 7 Input: 0 Terminated
Normal case
Input:
3 6 9 0
Expected Output:
Input: 3 Input: 6 Input: 9 Input: 0 Terminated
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here
sc.close();
}
}
0 B / 5 MB
You have 10 free executions remaining
