4.코딩 연습 문제:
- 2차원 배열 4 * 3 을 선언하고, 각각의 방을 랜덤으로 값을 넣은뒤 모두 출력하시오.
class ArrRandom {
private static final int INDEX_FIRST = 4;
private static final int INDEX_SECOND = 3;
private static double random() {
return Math.random();
}
public static void main(String[] args) {
double[][] arrRandom = new double[INDEX_FIRST][INDEX_SECOND];
StringBuilder print = new StringBuilder();
for (int i = 0; i < INDEX_FIRST; i++) {
for (int j = 0; j < INDEX_SECOND; j++) {
arrRandom[i][j] = random();
print.append(arrRandom[i][j]);
print.append(" ");
};
print.append("\n");
};
System.out.print(print);
}
}
//
// print
//
0.8241809097221745 0.8345717176081866 0.4344396833101133
0.10558151266515803 0.3667412400610325 0.7009359343275011
0.6384126867871407 0.7514006782698701 0.4817299032014979
0.798995958701251 0.18613992971104754 0.8878757634798718