Math.pow(x, 2)은 x의 2의 제곱을 구해주는 클래스
1. 양의 정수 n이 x의 제곱인지 비교 (n == Math.pow(x, 2))
2. true값이라면 (x+1)의 제곱을 출력 (Math.pow(x+1), 2))
3. false값이라면 -1을 출력
제곱시 값이 int형의 범위를 넘어갈 수 있으므로, 메소드의 반환형을 long형으로 변경**
class Solution {
public long solution(long n) {
double x = (int)Math.sqrt(n);
long answer = 0;
if(n == Math.pow(x, 2)) {
answer = (long)Math.pow((x + 1), 2);
}
else if(answer == 0)
answer = -1;
return answer;
}
}
Math.pow(x, n제곱)