본문 바로가기

Algorithm/Baekjoon

[백준_JAVA] 2908 상수

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str1 = sc.next();
		String str2 = sc.next();
		
		String sb1 = new StringBuffer().append(str1).reverse().toString();
		String sb2 = new StringBuffer().append(str2).reverse().toString();
		
		int num1 = Integer.parseInt(sb1);
		int num2 = Integer.parseInt(sb2);
		
		System.out.println(num1 > num2 ? num1 : num2);
	}
}

StringBuffer을 이용해 값을 reverse 해주었다.

'Algorithm > Baekjoon' 카테고리의 다른 글