Skip to content

Instantly share code, notes, and snippets.

@ksy90101
Created December 6, 2019 03:12
Show Gist options
  • Save ksy90101/73af42ea929e44c821b4a2191fb520e8 to your computer and use it in GitHub Desktop.
Save ksy90101/73af42ea929e44c821b4a2191fb520e8 to your computer and use it in GitHub Desktop.
[프로그래머스] 자바 중급 - Part2. java.lang패키지 - Math
package Part2;
public class MathExam {
public static void main(String[] args) {
// Math 클래스 : 수학 계산을 위한 클래스
// cos, sin, tan, abs, random....
// 생성자 자체가 private로 되어 있기 때문에 new 연산자를 이용하여 객체를 생성할 수 없음
// 그러나 메소드가 모두 static으로 정의되어 있기때문에 객체를 생성하지 않아도 사용 가능
int value1 = Math.max(5, 30); // 두 값 중에 큰 값을 호출
System.out.println(value1);
int value2 = Math.min(5, 30); // 두 값 중에 작은 값을 호출
System.out.println(value2);
System.out.println(Math.abs(-10)); // 절대값 호출
System.out.println(Math.random()); // 랜덤값 호출(return double) - 0 ~ 1.0미만
System.out.println(Math.sqrt(25)); // 제곱근 호출
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment