본문 바로가기
java&eclipse 코딩 알고리즘/20231130

RandomTest

by 몽상크리에이터 2023. 12. 13.

package k20231130;

 

import java.util.Random;

 

public class RandomTest {

 

public static void main(String[] args) {

 

// Math.random() : 0이상이고 1미만인 무작위 수(난수)를 발생시킨다.

System.out.println((int) (Math.random() * 45) + 1);

System.out.println((int) (Math.random() * 45) + 1);

System.out.println((int) (Math.random() * 45) + 1);

System.out.println((int) (Math.random() * 45) + 1);

System.out.println((int) (Math.random() * 45) + 1);

System.out.println((int) (Math.random() * 45) + 1);

 

// Random 클래스

Random random = new Random();

System.out.println(random.nextDouble());

System.out.println(random.nextInt(45) + 1);

System.out.println(random.nextInt(45) + 1);

System.out.println(random.nextInt(45) + 1);

System.out.println(random.nextInt(45) + 1);

System.out.println(random.nextInt(45) + 1);

System.out.println(random.nextInt(45) + 1);

 

 

 

 

 

 

 

 

 

 

}

 

 

}

'java&eclipse 코딩 알고리즘 > 20231130' 카테고리의 다른 글

ScannerTest2  (0) 2023.12.13
ScannerTest  (0) 2023.12.13
MukJjiBba  (0) 2023.12.13
LeapYearTest  (0) 2023.12.13
IfTest  (0) 2023.12.13