Jam's story

[프로그래머스] 제곱수판별하기 java 본문

코딩테스트/프로그래머스

[프로그래머스] 제곱수판별하기 java

애플쩀 2022. 12. 24. 11:56
	 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();

Comments