Skip to content

Commit c2e25ef

Browse files
committed
Example of Input and Output for a Two Dimensional Array
1 parent f5ea326 commit c2e25ef

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

‎src/Arrays/MultiDimensionArray.java‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package Arrays;
22

3+
import java.util.Arrays;
4+
import java.util.Scanner;
5+
36
public class MultiDimensionArray {
47
public static void main(String[] args) {
58
/*
@@ -12,9 +15,30 @@ public static void main(String[] args) {
1215
int[][] multiDimentionalArray = new int[3][3];
1316

1417
int [] [] array2D = {
15-
{1,2,3},
16-
{4,5},
17-
{7,8,9}
18+
{1,2,3},//0th index
19+
{4,5},// 1st index
20+
{6,7,8,9} // 2nd Index
1821
};
22+
23+
//input
24+
Scanner input = new Scanner(System.in);
25+
// System.out.println("Enter the Number:");
26+
27+
for (int row = 0; row < array2D.length; row++){
28+
// System.out.print("Please Enter the Number: ");
29+
for (int column = 0; column < array2D[row].length; column++){
30+
// System.out.print("Please Enter row " + row + " and" + " Coloumn " + column + " Number ");
31+
int number = input.nextInt();
32+
array2D[row][column] = number;
33+
}
34+
}
35+
//Output
36+
for (int[] ints : array2D) {
37+
// System.out.print("Please Enter the Number: ");
38+
for (int anInt : ints) {
39+
System.out.print(anInt + " ");
40+
}
41+
System.out.println(" ");
42+
}
1943
}
2044
}

0 commit comments

Comments
 (0)