Skip to content

Commit b20d73c

Browse files
authored
Create twoDimensionArray.java
1 parent 2f97f9d commit b20d73c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

apShenanigans/twoDimensionArray.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
public class twoDimensionArray {
3+
// two dimension array notes
4+
public static void main(String[] args) {
5+
int[][] numbers = {{1, 2, 3}, {4, 5, 6}};
6+
// [columns][rows]
7+
// 1 2 3
8+
// 4 5 6
9+
10+
System.out.println(numbers[0].length); // returns 3 -> rows length
11+
System.out.println(numbers.length); // returns 2 -> columns length
12+
13+
numbers[0][1] = 2;
14+
15+
for(int[] rowOfStrings : numbers) { // column is y, this loops to the next 1D array within the 2D array
16+
for(int s : rowOfStrings) { // row is x, this loop checks every seperate 1D array
17+
System.out.print(s + " "); // each value in a row is separated
18+
}
19+
System.out.println(); // makes a gap between each 1D array via nextLine.
20+
}
21+
22+
String [][] array = new String [2][3];
23+
// [columns][rows]
24+
25+
System.out.println(array[0].length); // returned 3
26+
System.out.println(array.length); // returned 2
27+
28+
29+
30+
31+
32+
}
33+
}
34+

0 commit comments

Comments
 (0)