본문 바로가기

콩's EDUCATION/콩's JAVA_RUN

Math 함수

Math 함수 이용하기


 

public class MathTest {
 public static void main(String[] args) {
  // static final public
  // 변수이름 ; 소문자 명사
  // final 변수 (=상수) 이름 ; 대문자 구성 ; read-only만 가능
  System.out.println("원주율= "+Math.PI);
  System.out.println("자연로그 = "+Math.E);
  System.out.println("첫번째 난수 = "+(int)((Math.random())*100));
  System.out.println("두번째 난수 = "+(int)((Math.random())*100));
  System.out.println("-100의 절대값 = "+Math.abs(-10.3));
  System.out.println("2의 3제곱근 값 = "+Math.pow(2,3));
  System.out.println("루트 3의 값 = "+Math.sqrt(3));
  System.out.println("반올림 값 = "+Math.round(3.242345));
 }
}

 

 

 

MathTest.java