본문 바로가기

프로그래밍언어/알고리즘

백준 2908 상수_JAVA

https://www.acmicpc.net/problem/2908

 

2908번: 상수

상근이의 동생 상수는 수학을 정말 못한다. 상수는 숫자를 읽는데 문제가 있다. 이렇게 수학을 못하는 상수를 위해서 상근이는 수의 크기를 비교하는 문제를 내주었다. 상근이는 세 자리 수 두

www.acmicpc.net

 

 

 

 


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        a = reverse(a);
        b = reverse(b);

        if(a > b){
            System.out.println(a);
        }else{
            System.out.println(b);

        }

    }


     static  int reverse(int num ){

        int result = 0;

        while(num != 0 ){  //5432 - 543
            result = result * 10 + num % 10; // 0 + 2 /  20+3   / 230 + 4 / 2340 + 5
            // System.out.println(result) 2출력  /  23출력  / 234출력   / 2345출력
            num /= 10 ;
            // System.out.println("a= " + a);  543  / 54  / 5  / 0
        }

        return result;

    }


}