import java.math.*; class Solution { public int[] solution(int n, int m) { int[] answer = new int[2]; BigInteger a = BigInteger.valueOf(n); BigInteger b = BigInteger.valueOf(m); BigInteger gcd = a.gcd(b); answer[0] = gcd.intValue(); answer[1] = (n*m)/answer[0]; return answer; } } Bigint 함수를 사용한 이유는 간편하게 최대공약수를 구할 수..
공통점 : valueOf()와 parseInt(), 두 메서드는 String을 Int로 반환합니다. 차이점 :Integer.valueOf(String) , 입력된 문자열을 Integer 객체로 반환합니다.문자열을 Integer로 Wrapping한 객체를 생성하는 것이고, 이 메서드는 auto-boxing 기능을 사용하여자동으로 변환합니다. 반환된 Integer 객체는 참조 타입이므로 Null 값을 가질 수 있습니다. Intger.parseInt(String) , 입력된 문자열을 Int 로 변환하여 기본 타입인 Int로 반환합니다.문자열을 정수로 변환하는 메서드 입니다. 하지만 기본 타입인 Int 이므로 Null 값을 가질 수 없습니다. Int 와 Integer :Int는 기본 타입으로, 메서드를 호출할 ..