Contoh array dua dimensi pada Java
class ArrayDuaDimensi{
public static void main (String[] args)
{
int[][] angka = new int[5][3];
for (int i=0; i<angka.length; i++)
for (int j=0; j<angka[i].length; j++)
angka[i][j] = (int)(Math.random()*100);
System.out.println("Data array dua dimensi:\n");
for (int i=0; i<angka.length; i++)
{
for (int j=0; j<angka[i].length; j++)
System.out.print(angka[i][j] + " ");
System.out.println();
}}}
Output :
public static void main (String[] args)
{
int[][] angka = new int[5][3];
for (int i=0; i<angka.length; i++)
for (int j=0; j<angka[i].length; j++)
angka[i][j] = (int)(Math.random()*100);
System.out.println("Data array dua dimensi:\n");
for (int i=0; i<angka.length; i++)
{
for (int j=0; j<angka[i].length; j++)
System.out.print(angka[i][j] + " ");
System.out.println();
}}}
Output :
Tidak ada komentar: