网易面试之对于一个整数X,定义操作rev(X)为将X按数位翻转过来,并且去除掉前导0

时间:2022-02-19 22:23:20
对于一个整数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.*;
public class Main{
public static void main(String[] args){
Scanner reader = new Scanner(System.in);
int x = reader.nextInt();
int y = reader.nextInt();
System.out.println(rev(rev(x)+rev(y)));
}

public static int rev(int x){
StringBuffer buffer = new StringBuffer(x+"");
buffer.reverse();
return Integer.valueOf(buffer.toString());
}
}