'난수'란 ? 임의의 수.
Math.random() : 0<=난수<1 사이의 난수를 발생. (실수)
Math.random() * 100; 0<=수<100 //
int n;
int cnt;
cnt=0;
while(cnt<100) {
cnt=0;
n = (int)(Math.random() * 100) + 1; // +1을해야 1부터 100까지임.
if(cnt%10==0){
System.out.println();
}
}
출력은 한 줄에 10개씩.
'쌍용강북교육센터 > 7월' 카테고리의 다른 글
0708_Ex08_for :1~100까지 홀수합, 짝수합, 3의 배수합 ... (0) | 2021.07.09 |
---|---|
0708_Ex05_for : 1~100까지의 합 (0) | 2021.07.09 |
0708_Ex03_while : 2~9사이의 수를 입력받아 입력받은 수의 구구단 구하기 (0) | 2021.07.08 |
0708_Ex02_while : while문과 Do~while 문 비교 (0) | 2021.07.08 |
0708_Ex01_while : 1+2+3+...+n 합이 100을 넘는 최소의 n 구하기 (0) | 2021.07.08 |