154k views
0 votes
How to create a two dimensional array in java, which can hold strings and integers.

1 Answer

4 votes

Hello, the following code is a simple program that belongs to a Java program. You can check it out and if you have any question(s), then feel free to ask in comments!

Good luck!

class HelloWorld {

public static void main(String[] args) {

//Let define our variables to initialize the 2d array

int raw=2;

int column=3;

//int 2d array can be defined as;

int[][] array1 = new int[raw][column];

//string 2d array can be defined as;

String[][] array2 = new String[raw][column];

//Assign some values.

array1[0][1]=25;

array2[0][1]="Hello world!";

//Printing section.

System.out.println(array1[0][1]);

System.out.println(array2[0][1]);

}

}

User Demitrius Nelon
by
5.0k points