방명록
- 임의의 정수 만들기 Math.random()2021년 03월 18일 13시 53분 03초에 업로드 된 글입니다.작성자: 원2728x90반응형
public class Test003 { public static void main(String[] args) { // Math.random() // 1. double type의 랜덤 수를 발생 // 2. 1미만 0이상인 수 // 3. 테스트 : System.out.println(Math.random()); double fNum = Math.random(); System.out.println(Math.random()); System.out.println(Math.random()); System.out.println(Math.random()); System.out.println(Math.random()); System.out.println(Math.random()); System.out.println(Math.random()); int iNum; iNum = (int)(Math.random() * 45); System.out.println(iNum); iNum = (int)(Math.random() * 45); System.out.println(iNum); iNum = (int)(Math.random() * 45); System.out.println(iNum); iNum = (int)(Math.random() * 45); System.out.println(iNum); iNum = (int)(Math.random() * 45); System.out.println(iNum); iNum = (int)(Math.random() * 45); System.out.println(iNum); // 로또 } }
* 0~45이기 때문에 44로 바꾼후 +1을 하면 됨.
728x90반응형'Language > Java' 카테고리의 다른 글
for 문3 (0) 2021.03.18 for 문 2 (0) 2021.03.18 for 문_1 (0) 2021.03.18 for 문 (0) 2021.03.18 switch문2 (0) 2021.03.18 switch문 (0) 2021.03.18 다음글이 없습니다.이전글이 없습니다.댓글