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// how to fill a 2d array java
2public class Fill2dArrayExample
3{
4 public static void main(String[] args)
5 {
6 int[][] arrNumbers = new int[3][3];
7 for(int a = 0; a < 3; a++)
8 {
9 for(int b = 0; b < 3; b++)
10 {
11 arrNumbers[a][b] = (int) (Math.random() * 6) ;
12 }
13 }
14 for(int x = 0; x < 3; x++)
15 {
16 for(int y = 0; y < 3; y++)
17 {
18 System.out.print(arrNumbers[x][y] + " ");
19 }
20 System.out.println();
21 }
22 }
23}
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}
1int[][] multiples = new int[4][2]; // 2D integer array with 4 rows
2 and 2 columns
3String[][] cities = new String[3][3]; // 2D String array with 3 rows
4 and 3 columns
1ships: [
2 { locations: [0, 0, 0], hits: ["", "", ""] },
3 { locations: [0, 0, 0], hits: ["", "", ""] },
4 { locations: [0, 0, 0], hits: ["", "", ""] }
5 ],
1ships: [
2 { locations: [0, 0, 0], hits: ["", "", ""] },
3 { locations: [0, 0, 0], hits: ["", "", ""] },
4 { locations: [0, 0, 0], hits: ["", "", ""] }
5 ],
6