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
Normal case
Input:
150 40 60 70
Expected Output:
[0.003s][warning][perf,memops] Cannot use file /tmp/hsperfdata_tesh/1310092 because it is locked by another process (errno = 11) Current: 40pt (Target: 150pt) Current: 100pt (Target: 150pt) Current: 170pt (Target: 150pt) Target reached!
Normal case
Input:
80 25 30 35
Expected Output:
Current: 25pt (Target: 80pt) Current: 55pt (Target: 80pt) Current: 90pt (Target: 80pt) Target reached!
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
