Algorithm🧠/Programmers

[프로그래머스] [PCCE 기출문제] 2번 / 출력 (java)

개발자겨려 2024. 5. 6. 22:34
문제

[프로그래머스] [PCCE 기출문제] 2번 / 출력 (java)

 

풀이
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int c = sc.nextInt();

        //풀이 1
        int b_square = (int) (Math.pow(c, 2) - Math.pow(a, 2));

        //풀이 2
        //int b_square = (c - a) * (c + a);

        System.out.println(b_square);
    }

 

 

해설

Math.pow() 메소드는 입력값과 출력값은 모두 double형이며 Math.pow(대상숫자,지수)를 넣어주면 된다