Math.random() 사용(출력)해보기
public class MathRandom {
public static void main(String[] args) {
System.out.println(Math.random());
}
}
0.00000000000000000 - 0.9999999999999999 까지의 랜덤한 소수값을 갖는다. 소수점 16자리까지
정수값을 얻기 위해 Math.random() * __
를 하면 된다.
0-9의 정수값을 얻기 위해 * 10을 하고, 자료형을 int로 다운캐스팅 해준다. 형변환 : https://www.notion.so/1-casting-75abec823c384c22bd06c9b790c1fc27?pvs=4
public class MathRandom {
public static void main(String[] args) {
System.out.println((int)(Math.random()*10));
}
}