[프로그래머스/Java] Lv.1 정수 제곱근 판별
문제 풀이 1 2 3 4 5 6 7 8 9 10 11 12 class Solution { public long solution(long n) { long answer = 0; if (Math.sqrt(n) % 1 == 0) { //n의 제곱근을 1로 나누어 떨어지면 answer = (long) Math.pow(Math.sqrt(n)+1, 2); //n의 제곱근에 1을 더하고 제곱을 함 } else { answer = -1; //1로 나누어떨어지지 않으면 -1 } return answer; } } Colored by Color Scripter cs