【简单】数字翻转

对于一个整数X,定义操作rev(X)为将X按数位翻转过来,并且去除掉前导0。例如:
如果 X = 123,则rev(X) = 321;
如果 X = 100,则rev(X) = 1.
现在给出整数x和y,要求rev(rev(x) + rev(y))为多少?

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
    public static int revs(int x){
        int d;
        int ans=0;
        while(x!=0){
            d = x % 10;
            ans = ans*10+d;
            x = x/10;
        }
        return ans;
    }
    public static int rev(int x){
        StringBuffer sc = new StringBuffer(String.valueOf(x));
        sc = sc.reverse();
        return Integer.valueOf(sc.toString());
    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner cin = new Scanner(System.in);
        while(cin.hasNext()){
            int x = cin.nextInt();
            int y = cin.nextInt();
            System.out.println(revs(revs(x)+revs(y)));
        }
    }
}

你可能感兴趣的:(简单)