# Array multidimensi

unknown
java
3 years ago
1.2 kB
4
Indexable
Never
```import java.util.stream.*;
public class Array_MD
{
public static void main(String[] args)
{
int[][] nilaiArray = { {1,4,5,1,4}, {4,2,5,1,5}, {2,5,1,2}}; // Ini Array 2 dimensi
int sum = 0;
int [][][] nilaiArray_3 =
{
{
{3,6,1},
{5,3,6},
{6,4,8}
},
// Array 3 Dimensi
{
{6,4,2},
{4,6,2},
{4,2}
}
};

System.out.println ("Ini 2 Dimensi");
for (int i = 0; i < nilaiArray.length;i++)
for (int a = 0; a < nilaiArray[i].length;a++)
{
System.out.println ("[" + i + "]" + "[" + a + "]" + ": " + nilaiArray[i][a]);   // Untuk 2 Dimensi
sum += nilaiArray[i][a];

}
System.out.println ("Total nilai array nya adalah: " + sum);
System.out.println ("Jumlah elemen array nya adalah: : " + nilaiArray.length);

System.out.println( );

System.out.println ("\nIni 3 Dimensi");
for (int b = 0; b < nilaiArray_3.length; b++)
for (int c = 0; c < nilaiArray_3[b].length;c++)										// Untuk 3 Dimensi
for (int d = 0; d < nilaiArray_3[c].length;d++)
{
System.out.println ("[" + b + "]" + "[" + c + "]" + "[" + d + "]" + "; " + nilaiArray_3[b][c][d]);
}
}
}```