수학에 관련된 함수를 사용할 수 있다.
package ex08;
public class Ma01 {
    public static void main(String[] args) {
        //abs(절대값)
        System.out.println(Math.abs(-1));
        //min, max (최소, 최대)
        System.out.println(Math.min(5, 10));
        System.out.println(Math.max(5, 10));
        //pow (거듭제곱)
        System.out.println(Math.pow(2, 16));
        //round(반올림), ceil(올림), floor(내림)
        System.out.println(Math.floor(10.3));
        //sqrt(제곱근)
        //4의 제곱근은 2
        //16의 제곱근은 4
        //5의 제곱근은? 계산안됨 ==== 루트5
        System.out.println(Math.sqrt(5));
        //random(랜덤)
        int n1 = (int) (Math.random() * 10);
        System.out.println(n1);
        //log
        //2를 "몇 번 곱해야(x)" 16이 되나 = 4번
        //2를 "몇 번 곱해야(x)" 256이 되나 = 8번
        //2를 "몇 번 곱해야(x)" 15이 되나 = 계산안됨(3<x<4) ==== (log 15 = ?(x))
        //log16 = 4
        //log15 = log15
        //5의 거듭제곱 -> 루트5
        //64의 거듭제곱 -> 8
        System.out.println(Math.log(15));
    }
}
Share article