Jam's story
[프로그래머스] 제곱수판별하기 java 본문
public static int solution(int n) {
if(n%Math.sqrt(n)==0) {
return 1;
}else {
return 2;
}
}
public static int solution(int n) {
Double x=Math.sqrt(n);
if(x==x.intValue()) {
return 1;
}else {
return 2;
}
public static int solution(int n) {
return Math.sqrt(n)%1==0? 1:2;
}
int -> String
1. Integer.toString(int 값)
2.Integer.valueOf(int값)
String -> int
1.Integer.valueOf(String값)
Double -> int
.intValue() 사용
Math.around를 써주면 long 형으로 바뀐다.여기서 int형으로 변환해준다.
int a=(int)Math.around();
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 자릿수 더하기 java (0) | 2022.12.26 |
---|---|
[프로그래머스] 크기가 작은 부분문자열 java (1) | 2022.12.24 |
[프로그래머스] 가장 가까운 같은 글자 java (0) | 2022.12.21 |
[프로그래머스] 세균증식 JAVA (0) | 2022.12.21 |
[프로그래머스] 문자열 정렬하기(2) JAVA (0) | 2022.12.21 |
Comments