Topic description:
For an integer X, define the operation rev(X) to digit-reverse X and remove leading zeros. For example:
if X = 123, then rev(X) = 321;
if X = 100, then rev(X) = 1.
Now given integers x and y, rev(rev(x) + rev(y)) is required to be How many?
if X = 123, then rev(X) = 321;
if X = 100, then rev(X) = 1.
Now given integers x and y, rev(rev(x) + rev(y)) is required to be How many?
Enter description:
Input is one line, x, y (1 ≤ x, y ≤ 1000), separated by spaces.
Output description:
Output the value of rev(rev(x) + rev(y))
Example 1
enter
123 100
output
223
package p2; import java.util.Scanner; /** * Topic description * For an integer X, define the operation rev(X) to digit-reverse X and remove leading zeros. E.g: * if X = 123, then rev(X) = 321; * If X = 100, then rev(X) = 1. * Now given integers x and y, what is the required rev(rev(x) + rev(y))? * @author Guozhu Zhu * @date 2018/4/26 * @version 1.0 * */ public class Test04 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int i = in.nextInt(); int j = in.nextInt(); System.out.println(getRev(i) + getRev(j)); } public static int getRev(int num) { int x = 0; while (num != 0) { x = 10*x + num%10; num = num/10; } return x; } }