it공부/Java

Math.random() 랜덤한 숫자

콩쨈 2020. 7. 5. 22:10
반응형

Math.random() 

랜덤한 숫자를 나오게 하는 코드 라이브러리

 

(int) (Math.random() * 100);   --99까지 랜덤한 숫자

 

(int) (Math.random() * 100)+1;  --100까지 랜덤한 숫자
package a_variable;

public class RandomClass {
	public static void main(String[] args) {

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

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

		 

		}

		}

 

반응형

'it공부 > Java' 카테고리의 다른 글

변수선언 : 명명규칙  (0) 2020.07.05
변수의 타입  (0) 2020.07.05
연산자  (0) 2020.07.05
산술연산자 사칙대입  (0) 2020.07.05
조건문 if switch  (0) 2020.07.05