006-003-001
While Loop: Accumulate Points
Easy
Problem Description
while loop: Accumulate Points
In this problem, you will create a program that reads a target points value and multiple rounds of earned points, displaying the running total after each round until the total reaches the target, then prints "Target reached!"
Learning Objective: Repeat while condition met with while loop
Create program that inputs target points and earned points, repeatedly displaying until total reaches target. Use while loop to repeat while total under target.
Input
Line 1: Target points (integer)
Line 2 onwards: Earned points (integer, multiple lines)
Output
Current: [total]pt (Target: [target]pt)
Current: [total]pt (Target: [target]pt)
...
Target reached!
Examples
Example 1: Target reached in 3 rounds
Input:
100
30
50
25
Output:
Current: 30pt (Target: 100pt)
Current: 80pt (Target: 100pt)
Current: 105pt (Target: 100pt)
Target reached!
Example 2: Target reached in 1 round
Input:
50
60
Output:
Current: 60pt (Target: 50pt)
Target reached!
Example 3: Exactly reaching target
Input:
100
100
Output:
Current: 100pt (Target: 100pt)
Target reached!
Test Cases
※ Output examples follow programming industry standards
Input:
100 30 50 25
Expected Output:
Current: 30pt (Target: 100pt) Current: 80pt (Target: 100pt) Current: 105pt (Target: 100pt) Target reached!
Input:
50 60
Expected Output:
Current: 60pt (Target: 50pt) Target reached!
Input:
100 100
Expected Output:
Current: 100pt (Target: 100pt) Target reached!
Input:
200 50 50 50 60
Expected Output:
Current: 50pt (Target: 200pt) Current: 100pt (Target: 200pt) Current: 150pt (Target: 200pt) Current: 210pt (Target: 200pt) Target reached!
❌ Some tests failed
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 9 free executions remaining
