004-008-004
Creating Multidimensional Arrays: 2D Arrays
Medium
Problem Description
Creating Multidimensional Arrays: 2D Arrays
Learning Objective: Understand how to declare and initialize 2D arrays
Overview
Create a program that creates a 3x2 two-dimensional array, sets values, and outputs them.
Specifications
- Create a 3x2 int 2D array
- Assign values: {{1, 2}, {3, 4}, {5, 6}}
- Output all elements row by row
Output Format
Row 0: 1, 2
Row 1: 3, 4
Row 2: 5, 6
Test Cases
※ Output examples follow programming industry standards
Input:
Expected Output:
Row 0: 1, 2 Row 1: 3, 4 Row 2: 5, 6
❌ Some tests failed
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
›
⌄
⌄
⌄
⌄
⌄
⌄
public class Main {
// メインメソッドを定義
public static void main(String[] args) {
// と initialize 2D 配列を作成
int[][] matrix = {
{1, 2},
{3, 4},
{5, 6}
};
// 各行を出力
for (int i = 0; i < matrix.length; i++) {
System.out.print("Row " + i + ": ");
for (int j = 0; j < matrix[i].length; j++) {
// if j は 大きい より 0をチェック
if (j > 0) {
System.out.print(", ");
}
System.out.print(matrix[i][j]);
}
System.out.println();
}
}
}
0 B / 5 MB
You have 10 free executions remaining
