본문 바로가기

코딩테스트

[프로그래머스/자바] 제곱수 판별하기

    문제    

 

    코드    

class Solution {
    public int solution(int n) {
       return (Math.sqrt(n) % 1 == 0) ? 1 : 2;
    }
}

 

💘 제곱근 구하기

출처: Java Platform SE 8

- Math.sqrt() 메소드는 입력값과 출력값은 모두 double형