006-005-002

Break and Continue: Loop Control

Easy

Problem Description

Break and Continue: Loop Control

In this problem, you will read an upper limit, a skip divisor, and a stop value from standard input, then loop from 1 to the upper limit while skipping multiples of the divisor with continue and stopping at the stop value with break.

Learning Objective: Understand how to control loop flow using break and continue statements

Overview

Read three integers from standard input and create a program that skips or exits early based on conditions.

Input Format

n      (loop upper limit: 1 to n)
skip   (skip multiples of this value)
stop   (exit when this value is reached)

Specifications

  • Loop from 1 to n
  • If i equals stop: print "Stopped at {stop}" and exit with break
  • If i is a multiple of skip: skip with continue
  • Otherwise: print "Processing: {i}"
  • If stop is greater than n, the "Stopped at" line is not printed

Input/Output Example

Input:
10
3
8

Output:
Processing: 1
Processing: 2
Processing: 4
Processing: 5
Processing: 7
Stopped at 8

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
12
3
9
Expected Output:
Processing: 1
Processing: 2
Processing: 4
Processing: 5
Processing: 7
Processing: 8
Stopped at 9
Normal case
Input:
10
2
7
Expected Output:
Processing: 1
Processing: 3
Processing: 5
Stopped at 7

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 10 free executions remaining