Random 클래스를 활용한 랜덤값 출력하기
1. random.nextDouble() 랜덤한 실수값 출력
2. random.nextInt() 랜덤한 정수값 출력
3. random.nextInt(100) + 40 : 40부터 140까지의 랜덤한 정수값 출력
random.nextInt() => 0부터 정수의 최대값까지가 범위
package day0110;
// Random 클래스
// Random 클래스는 우리가 랜덤숫자(=난수)가 필요할 때 사용하는 클래스이다.
import java.util.Random;
public class Ex07Random {
public static void main(String[] args) {
Random random = new Random();
System.out.println(random.nextDouble());
System.out.println(random.nextDouble());
System.out.println(random.nextDouble());
System.out.println(random.nextDouble());
System.out.println(random.nextInt());
System.out.println(random.nextInt());
System.out.println(random.nextInt());
System.out.println(random.nextInt());
System.out.println(random.nextInt(100) + 40);
System.out.println(random.nextInt(100) + 40);
System.out.println(random.nextInt(100) + 40);
System.out.println(random.nextInt(100) + 40);
}
}
'JX405기_비트 > Java' 카테고리의 다른 글
Day02-8 Lotto 번호 생성기 (배열 사용) (0) | 2023.01.15 |
---|---|
Day02-7 Random 클래스를 활용한 Lotto번호 출력 (배열 없이) (0) | 2023.01.15 |
Day02-5 Array 배열 (0) | 2023.01.15 |
Day02-4 전역 상수를 활용한 학생 관리 프로그램 작성 (0) | 2023.01.12 |
Day02-3 학생 관리 프로그램 작성 (0) | 2023.01.12 |