0
How to print two dimensional array In java
if we have. int [ ][ ]arr = {{1,5,8}, {46,5,88}};
4 odpowiedzi
+ 3
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
System.out.println(arr[i][j]);
}
}
+ 1
An easy way to do that is to use the utility deepToString
as written by 'Vidhya - Vidhyadharan' in:
http://stackoverflow.com/questions/7782080/java-printing-two-dimensional-array
import java.util.Arrays;
public class Program
{
public static void main(String[] args) {
int twoD[][] = new int[4][];
twoD[0] = new int[1];
twoD[1] = new int[2];
twoD[2] = new int[3];
twoD[3] = new int[4];
System.out.println(
Arrays.deepToString(twoD)
);
}
}
0
using nested loop :))
0
I used bested loop , but doesn't work