Fatihul Ulum Community of Knowledge
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Array 1 dimensi

Go down

Array 1 dimensi Empty Array 1 dimensi

Post  arip Sun Nov 08, 2009 6:14 am

Code:
class kasus1
{public static void main(String[] args)
{ int[] x = {12, 3, 14, 6, 17, 7, 5, 9, 11, 10, 4, 2};
int[][] y = new int[4][3];
//memasukkan elemen array x pada index i ke dlm array 2 dimensi
for(int i=0; i<12; i++)
y[i/3][i%3] = x[i];
//menampilkan elemen-elemen array 2 dimensi tadi ke layar
for(int i=0; i<4; i++)
{ for(int j=0; j<3; j++)
System.out.print(y[i][j]+"\t");
System.out.println();
}
}
}

arip
arip
Pejuang
Pejuang

Jumlah posting : 36
Registration date : 05.03.09

Kembali Ke Atas Go down

Kembali Ke Atas

- Similar topics

 
Permissions in this forum:
Anda tidak dapat menjawab topik