자바 JAVA) 제곱과 제곱근 함수 Math.pow()와 Math.sqrt()

JangDongyul·2023년 5월 26일
0

JAVA

목록 보기
1/5

1. 자바에서 제곱을 다루려면
Math.pow(double 대상숫자, double 지수)를 사용하자

👉Math.pow() 에 대한 자바 공식 문서 링크

public class Pow {
    public static void main(String[] args) {
        System.out.println(Math.pow(10,2));
        //결과는 10의 2제곱인 100이 나온다.
    }
}

2. 자바에서 제곱근을 다루려면
Math.sqrt(double 대상숫자)를 사용하자

👉Math.sqrt( )에 대한 자바 공식 문서 링크

public class Sqrt {
    public static void main(String[] args) {
        System.out.println(Math.sqrt(4));
        //4의 제곱근인 2가 나온다.
    }
}

0개의 댓글