2013년 6월 25일 화요일

(130625) 2일차 MathRandom.java (랜덤 함수)

import java.util.Random;

public class MathRandom {

 public static void main(String[] args) {
  // 난수를 발생 시키는 기능 (5개 중에 1개밖에 안나옴)
  Random r = new Random();
  int result = r.nextInt(5)+1;
  System.out.println(result);

  int mathresult = (int)(Math.random()*10);
  System.out.println(mathresult);


  int mathresult2 = (int)(Math.random()*45);
  System.out.println(mathresult2);
 }
}