Random (2) 썸네일형 리스트형 Java - 11 [Random , Collections] Random class - 여러형태의 난수를 생성할 때 필요하다. public class RandomExample { public static void main(String[] args) { System.out.println("0.0 ~ 1.0 사이의 난수 1개 발생 : " + Math.random()); System.out.println("0 ~ 10 사이의 난수 1개 발생 : " + (int)((Math.random()*10000)%10)); System.out.println("0 ~ 100 사이의 난수 1개 발생 : " + (int)(Math.random()*100)); } } 위 코드를 보면 기본적으로 Math.random() 함수는 0.0에서 1.0사이의 난수를 발생 시킨다. setSeed(lo.. Java - 7 [클래스 메소드 - 인스턴스 메소드, String 클래스, Math, Random] 클래스 메소드 - 클래스 변수와 마찬가지로 클래스에 속한 메소드이다. 인스턴스 메소드는 인스턴스를 정의해야지만 썼는데 클래스 변수는 인스턴스를 정의하지 않고도 쓸수 있다. 왜냐하면 상수처럼 클래스에 속한 메소드 이므로 해당 클래스 이름을 직접 써서 호출이 가능하다는 것이다. public class Driver { public static void main(String[] args) { System.out.println(Math.abs(-10)); // 절댓값 System.out.println(Math.max(3, 7)); // 두 값 중 최댓값 System.out.println(Math.random()); // 0.0과 1.0 사이의 랜덤값 } } 이렇게 우리가 일반적으로 System.out.printl.. 이전 1 다음