문제
풀이
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(대상숫자,지수)를 넣어주면 된다
'Algorithm🧠 > Programmers' 카테고리의 다른 글
[프로그래머스] [PCCE 기출문제] 1번 / 출력 (java) (0) | 2024.04.12 |
---|