Skip to content

Commit 1d0c48a

Browse files
committed
11번째 문제
1 parent ac3156a commit 1d0c48a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/homework/Random.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package homework;
2+
3+
/*
4+
#문제 11번
5+
2차원 배열 random[4][4]을 생성하고,
6+
이 곳에 1~10까지의 범위의 정수를 랜덤하게 생성하여
7+
정수 16개를 배열에 저장한 후 화면에 출력
8+
9+
<조건>
10+
조건 1. 참고 ) 자바에서 0~0.999999 중에 하나의 수를 리턴해주는 함수 : Math.random()
11+
조건 2. getRandom()메서드를 이용하여 처리하라.
12+
조건 3. main구문은 다음과 같다
13+
*/
14+
public class Random {
15+
16+
public static void main(String[] args) {
17+
int[][] random = new int[4][4];
18+
getRandom(random);
19+
}
20+
21+
private static void getRandom(int[][] random) {
22+
for (int i = 0; i < random.length; i++) {
23+
for (int j = 0; j < random.length; j++) {
24+
random[i][j] = (int) (Math.random() * 10) + 1;
25+
System.out.print(random[i][j] + "\t");
26+
}
27+
System.out.println("");
28+
}
29+
30+
}
31+
32+
}

0 commit comments

Comments
 (0)