006-003-006

While Loop: Accumulate Points

Easy

Problem Description

While Loop: Accumulate Points

Learning Objectives

Bloom Level: Apply

Practical Goals

  1. Implement "repeat while condition met" processing with while loop
  2. Understand importance of accumulator variable initialization and update
  3. Set loop termination condition correctly
  4. Choose while loop over for loop when iteration count is unknown

Real-World Scenario

Scenario Type: Business

Business Context

You are on a point card app development team. You implement a feature where points accumulate with each purchase, displaying "Bonus earned!" when target points are reached.

This "goal-achievement loop" is used in game experience systems, savings apps, learning progress management, and many applications. Master loop processing when iteration count is unknown in advance.

Why This Matters

  • "Unknown iteration count loops" are frequent patterns in practice
  • Accumulation processing is basic for data analysis, aggregation, report generation
  • Correct loop design avoiding infinite loops is an essential skill

Problem Statement

Create program that inputs target points and earned points, repeatedly displaying until total reaches target.

Input

Line 1: Target points (integer)
Line 2 onwards: Earned points (integer, multiple lines)

Output

Current: [total]pt (Target: [target]pt)
...
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!
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
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