'난수구하기 및 수학함수'에 해당되는 글 1건

  1. 2012.07.29 난수구하기 및 수학함수

* double d = Math.random(); //난수 발생 범위(0.0 <= x < 1.0)
* java.util.Random r = new Random();
Int i = r.nextInt();//인트의 범위까지 정수형을 리턴한다.
int i1 = r.nextInt(100);//0~(100-1)까지의 숫자를 랜덤적으로 리턴한다.

package random;

import java.util.Random;

public class RandomTest {

 public static void main(String[] args) {
  Random r = new Random();
  System.out.println(r.nextInt());//int 범위에있는 모든 수를 random하게
  System.out.println(r.nextBoolean());
  System.out.println(r.nextDouble());;
  System.out.println(r.nextLong());
  int i = r.nextInt();
  while(i>=0){
   i = r.nextInt();
  }
  System.out.println(i);
  i = r.nextInt(10);//0~9까지 리턴
  while(i!=10){
   i = r.nextInt(10);
  }
  System.out.println(i);
 }

}
--------------------------------
================================================================

* 2012-3-26
* Java.math.BigDecimal - double로 표현이 안되는 부동 소숫점 표현  -> 구문 :  new (BigDecimal("10.5");
            BigInteger - long으로 표현이 안되는 정수를 표현

* project : day23
  package : number
  class : BigDecimalTest


package number;

import java.math.BigDecimal;

public class BigDecimalTest {
 public static void main(String[] args) {
  System.out.println(2.00-1.11);
  BigDecimal d1 = new BigDecimal("2.0");
  BigDecimal d2 = new BigDecimal("1.10");
  // + : add(), - : substract(), / : divide(), * : multiply()
  BigDecimal result  = d1.subtract(d2);
  double d = result.doubleValue();
  System.out.println(result +" : "+ d);
  //1 : 나눌 수, 2 : scale - 소숫점 이하 몇자리 까지보여줄것인지, 3 : 소숫점 이하 처리방식
  result = d1.divide(d2,3,BigDecimal.ROUND_CEILING);//소수점 3자리까지 나타내라.
  System.out.println("나눈 결과 : "+result);
 }
}

'프로그래밍 > JAVA프로그래밍' 카테고리의 다른 글

File I/O  (0) 2012.07.29
예외처리(Exception), try catch finally  (0) 2012.07.29
java 시간 날짜 처리  (0) 2012.07.29
String class, String buffer  (0) 2012.07.29
boxing, unboxing, wrapperClass  (0) 2012.07.29
Posted by 조은성
,