-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwoDimArray.java
More file actions
37 lines (27 loc) · 822 Bytes
/
Copy pathTwoDimArray.java
File metadata and controls
37 lines (27 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class TwoDimArray {
public static void main(String[] args) {
// two dimensional string array
int country = 2;
int colour = 2;
String[][] myArray = new String[country][colour];
// assign values
myArray[0][0] = "Ireland";
myArray[0][1] = "Green";
myArray[1][0] = "Sweden";
myArray[1][1] = "Blue";
// revised submission 27/09/15 using .length annotation
// output values using for loop
for (int c = 0; c < myArray.length; c++) {
for (int j = 0; j < myArray[c].length; j++) {
System.out.print(myArray[c][j] + "\t");
/* System.out.println(myArray[c][j]); */
}
}
// old submission
// output values using for loop
/*
* for(int i = 0; i < country; i++){ for(int j = 0; j < colour; j++){
* System.out.println(myArray[i][j]);
*/
} // end main
} // end class