006-005-011

break/continue: Labeled Loop Control

Hard

Problem Description

break/continue: Labeled Loop Control

In this problem, you will create a program that searches for a specific value in a 3x4 two-dimensional array using labeled break in nested loops and displays the found coordinates to standard output.

Learning Objective: Understand how to use labels to specify the target of break/continue in nested loops

Overview

A regular break terminates the innermost loop, but using labels allows direct termination of outer loops. This is useful for two-dimensional array searches and complex loop processing.

Specifications

Create a program that searches for a specific value in a 2D array and displays the found coordinates:

  1. Initialize a 3x4 two-dimensional array with these values:
    • Row 0: {1, 2, 3, 4}
    • Row 1: {5, 6, 7, 8}
    • Row 2: {9, 10, 11, 12}
  2. Initialize search target target with 7
  3. Label the outer loop with outer:
  4. Display "Searching [row][col]" during search
  5. When found, display "Found at [row][col]" and exit both loops with labeled break

Output Format

Searching [0][0]
Searching [0][1]
Searching [0][2]
Searching [0][3]
Searching [1][0]
Searching [1][1]
Searching [1][2]
Found at [1][2]

Test Cases

※ Output examples follow programming industry standards

Input:
Expected Output:
Searching [0][0]
Searching [0][1]
Searching [0][2]
Searching [0][3]
Searching [1][0]
Searching [1][1]
Searching [1][2]
Found at [1][2]
Input:
Expected Output:
Searching [0][0]
Searching [0][1]
Searching [0][2]
Searching [0][3]
Searching [1][0]
Searching [1][1]
Searching [1][2]
Found at [1][2]
Input:
Expected Output:
Searching [0][0]
Searching [0][1]
Searching [0][2]
Searching [0][3]
Searching [1][0]
Searching [1][1]
Searching [1][2]
Found at [1][2]
Input:
Expected Output:
Searching [0][0]
Searching [0][1]
Searching [0][2]
Searching [0][3]
Searching [1][0]
Searching [1][1]
Searching [1][2]
Found at [1][2]
❌ 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