public class study4 {
public static void main(String args[]) {
int number[][];
number = new int[4][4];
int rand[];
rand = new int[8];
for (int i = 0; i < number.length; i++) {
for (int b = 0; b < number.length; b++) {
number[i][b] = 0;
}
}
for (int i = 0; i < rand.length; i++) {
rand[i] = (int) Math.round(Math.random() * 9 + 1);
System.out.print(rand[i] + " ");
number[(int) Math.round(Math.random() * 3)][(int) Math.round(Math.random() * 3)] = rand[i];
}
System.out.println(""+"\n");
for (int i = 0; i < number.length; i++) {
for (int b = 0; b < number.length; b++) {
System.out.print(number[i][b] + " ");
}
}
}
}
출력결과 :
7 10 2 8 7 6 5 5
0 7 0 0 0 0 5 0 0 7 10 8 5 0 0 0
반응형