[JAVA] 난수 (Math.random)

Dawon Ruby Choi·2023년 8월 30일
0

Java

목록 보기
11/18
post-thumbnail
		Math.random(); // double 랜덤으로 반환 // 0<= math.random() < 1
		System.out.println(Math.random()); 
		
		//1~10 사이의 랜덤한 수 출력
		// 0단계 : 0 <= Math.random() < 1 // 0~0.99999999999
		// 1단계 : 0 <= Math.random()*10 < 10 // 0~9.99999999999
		// 2단계 : 1 <= Math.random()*10+1 < 11 // 1~10.99999999999
		// 3단계 : 1 <= (int)(Math.random()*10+1) < 11 // 1~10
		// 2단계와 3단계 순서가 바뀌어도 상관 없음
        

(2) toUpperCase / toLowerCase
if(user.toUpperCase().equals("Y")) { // 무조건 대문자로 변경
if(user.toLowerCase().equals("y")) { // 무조건 소문자로 변경
문자 열에서만 사용 가능 (char.At 사용 불가)

if (user == "Y" || user == "y")로 번거롭게 안써도 됨

profile
나의 코딩 다이어리🖥️👾✨

0개의 댓글