0

How to print two dimensional array In java

if we have. int [ ][ ]arr = {{1,5,8}, {46,5,88}};

4th Feb 2017, 4:39 PM
AbuAli
AbuAli - avatar
4 odpowiedzi
+ 3
for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { System.out.println(arr[i][j]); } }
4th Feb 2017, 5:04 PM
Adrian M. R.
Adrian M. R. - avatar
+ 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) ); } }
4th Feb 2017, 5:06 PM
Tashi N
Tashi N - avatar
0
using nested loop :))
4th Feb 2017, 5:13 PM
Biobii
Biobii - avatar
0
I used bested loop , but doesn't work
4th Feb 2017, 5:35 PM
AbuAli
AbuAli - avatar