카테고리 없음
[프로그래머스] 제곱수 판별하기
waveTocode
2023. 3. 30. 00:11
문제 설명
어떤 자연수를 제곱했을 때 나오는 정수를 제곱수라고 합니다. 정수 n이 매개변수로 주어질 때, n이 제곱수라면 1을 아니라면 2를 return하도록 solution 함수를 완성해주세요.

class Solution {
public int solution(int n) {
int answer = 0;
if((int)Math.sqrt(n)*(int)Math.sqrt(n)==n) answer=1;
else answer=2;
return answer;
}
}
New Learning!
Math.sqrt() 메서드
-인수를 넣으면 제곱근 출력
-결과는 실수형태