inblog logo
|
jjack1
    Java

    [JAVA] 11. 자바 Utils & Lib Ⅰ. JRE 라이브러리 import (3) Math

    최재원's avatar
    최재원
    Feb 14, 2025
    [JAVA] 11. 자바 Utils & Lib Ⅰ. JRE 라이브러리 import (3) Math
    Contents
    수학 관련 메서드1. abs(절대값)2. min(최소), max(최대)3. pow(거듭제곱)4. round(반올림), ceil(올림), floor(내림)5. sqrt(제곱근)6. random(랜덤)7. log(로그)

    수학 관련 메서드

    1. abs(절대값)

    System.out.println("절대값"); System.out.println(Math.abs(-1));
    notion image

    2. min(최소), max(최대)

    System.out.println("최소, 최대"); System.out.println(Math.max(1, 5)); System.out.println(Math.min(1, 5));
    notion image

    3. pow(거듭제곱)

    System.out.println("거듭제곱"); System.out.println(Math.pow(2, 16));
    notion image

    4. round(반올림), ceil(올림), floor(내림)

    System.out.println("반올림, 올림, 내림"); System.out.println(Math.round(10.3)); System.out.println(Math.ceil(10.3)); System.out.println(Math.floor(10.3));
    notion image

    5. sqrt(제곱근)

    // 4의 제곱근 2 // 9의 제곱근 3 // 5의 제곱근 ?System.out.println("제곱근"); System.out.println(Math.sqrt(5)); System.out.println(Math.sqrt(7)); System.out.println(Math.sqrt(8.9));
    notion image

    6. random(랜덤)

    // 0.0 <= n < 1.0 System.out.println("랜덤"); double n1 = Math.random() * 10 + 1; System.out.println((int) n1);
    notion image

    7. log(로그)

    // 2를 몇번 곱해야(x) 16이 되는가? 4 // 2를 몇번 곱해야(x) 256이 되는가? 8 // 2를 몇번 곱해야(x) 8이 되는가? 3 // log16 = 4 // log15 = log15 // 5의 거듭제곱 -> 루트5 // 64의 거듭제곱 -> 8 System.out.println("로그"); System.out.println(Math.log(15)); System.out.println(Math.log(16)); System.out.println(Math.log(16) / Math.log(2)); // log e 16 / log e 2 = log 2 16
    notion image
    Share article

    jjack1

    RSS·Powered by Inblog