docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/Math.html
java.lang์ ์ํด์๋ ํด๋์ค.
์ํ์์ ์์ฃผ ์ฌ์ฉํ๋ ์ ๋๊ฐ, ๋ฐ์ฌ๋ฆผ ๋ฑ์ ๋ฉ์๋๋ก ์ ๊ณตํ๋ค.
Math :
- Math.E : public static final double E / ์์ฐ๋ก๊ทธ e
- Math.PI : public static final double PI / ์์ฃผ์จ ํ์ด π
- static double random() : 0 ์ด์ 1 ๋ฏธ๋ง์ double๊ฐ ๋๋ค ๋ฐํ
- static int / long / double / float abs(int / long / double / float a) : ์ ๋๊ฐ ๋ฐํ
- static double round(double a) : ๋ฐ์ฌ๋ฆผ
- static long round(float a) : ๋ฐ์ฌ๋ฆผ
- static double floor(double a) : ๋ด๋ฆผ
- static double ceil(double a) : ์ฌ๋ฆผ
- static int / long / double / float max(int / long / double / float a, int / long / double / float b) : ์ต๋๊ฐ ๋ฐํ
- static int / long / double / float min(int / long / double / float a, int / long / double / float b) : ์ต์๊ฐ ๋ฐํ
- static double pow(double a, double b) : a์ b์ ๊ณฑ
- static double sqrt(double a) : a์ ์ ๊ณฑ๊ทผ, ๋ฃจํธ a
Math.random()
Math.abs(a)
Math.round(a)
Math.floor(a)
Math.ceil(a)
Math.max(a, b)
Math.min(a, b)
Math.pow(a, b)
Math.sqrt(a)
์์
public class MathEx {
public static void main(String[] args) {
System.out.println(Math.E);
System.out.println(Math.PI);
System.out.println();
int a = 2;
int b = 4;
double c = 2.31;
double d = 3.78;
System.out.println(Math.random());
System.out.println();
System.out.println(Math.abs(c) + " / " + Math.abs(d));
System.out.println();
System.out.println(Math.round(c) + " / " + Math.round(d));
System.out.println(Math.floor(c) + " / " + Math.floor(d));
System.out.println(Math.ceil(c) + " / " + Math.ceil(d));
System.out.println();
System.out.println(Math.max(a, b) + " / " + Math.min(a, b));
System.out.println();
System.out.println(Math.pow(a, b));
System.out.println(Math.sqrt(b));
}
}
์ถ๋ ฅ
2.718281828459045 3.141592653589793 0.936752083337916 2.31 / 3.78 2 / 4 2.0 / 3.0 3.0 / 4.0 4 / 2 16.0 2.0 |
์ฌ์ฉ ์ : nanarin.tistory.com/67