반응형
문제
문제 설명
- 입력받은 두 수를 거꾸로 뒤집어서 큰 숫자를 출력(출력도 뒤집힌 수로 출력)
- reverse할 때는
StringBuffer
를 이용했다. - 인풋받은 두 숫자를 리벌스하면서 의미없는 코드가 반복될 것 같아
reverse
함수를 따로 만들어 줬다.
성공 코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = reverse(sc.next());
int b = reverse(sc.next());
sc.close();
if (a > b)
System.out.println(a);
else
System.out.println(b);
}
public static int reverse(String str) {
StringBuffer sb = new StringBuffer(str);
sb = sb.reverse();
int result = Integer.parseInt(sb.toString());
return result;
}
}
반응형