1// two dimensional string array in java example
2public class TwoDimensionalStringArray
3{
4 public static void main(String[] args)
5 {
6 String[][] animals = {
7 { "Lion", "Tiger", "Cheetah" },
8 { "Deer", "Jackal", "Bear" },
9 { "Hyena", "Fox", "Elephant" } };
10 for(int a = 0; a < animals.length; a++)
11 {
12 System.out.print(animals[a][0] + " ");
13 for(int b = 1; b < animals[a].length; b++)
14 {
15 System.out.print(animals[a][b] + " ");
16 }
17 System.out.println();
18 }
19 }
20}
1// two dimensional array in java example program
2public class SimpleTwodimensionalArray
3{
4 public static void main(String[] args)
5 {
6 // declare and initialize two dimensional array
7 int[][] arrnumbers = {{2, 4},{6, 8},{10, 12}};
8 System.out.println("Two dimensional array in java: ");
9 for(int a = 0; a < 3; a++)
10 {
11 for(int b = 0; b < 2; b++)
12 {
13 System.out.println(arrnumbers[a][b]);
14 }
15 }
16 }
17}
1// Two dimensional array
2int a[2][3]= {
3 {1, 2, 3},
4 {4, 5, 6}
5 };
6
7 cout << a[1][1]; // Output is 5
8
9// Three dimensional array
10//[2] is elements; [3] is rows in elements; [4] is column in elemnents
11int a[2][3][2]= {
12 //Element 0
13 { {1, 2},
14 {2, 3},
15 {4, 5}
16
17 },
18
19
20 // Element 1
21 { {6, 7},
22 {8, 9},
23 {10, 11}
24
25 }
26 };
27
28 cout << a[0][1][1]; // Prints 3
1var iMax = 20;
2var jMax = 10;
3var f = new Array();
4
5for (i=0;i<iMax;i++) {
6 f[i]=new Array();
7 for (j=0;j<jMax;j++) {
8 f[i][j]=0;
9 }
10}
11
1var items = [
2 [1, 2],
3 [3, 4],
4 [5, 6]
5];
6console.log(items[0][0]); // 1
7console.log(items[0][1]); // 2
8console.log(items[1][0]); // 3
9console.log(items[1][1]); // 4
10console.log(items);