This Java Program we Reverse two Number and find the Sum of its Digits Using while Loop.While loop checks the condition first and then executes the statement here first we find the reminder and then Multiply reverse number by 10 and add remainder of number.Dividing number by 10 to access digit position.after that we sum the both reverse number.
public class ReverseThenSum {
public static void main(String[] args) {
int i = 123;
int j = 456;
int reverseOne = 0;
int reverseTwo = 0;
while (i != 0) {
int n = i % 10;
reverseOne = reverseOne * 10 + n;
i = i / 10;
}
while (j != 0) {
int m = j % 10;
reverseTwo = reverseTwo * 10 + m;
j = j / 10;
}
int reverseSum = reverseOne + reverseTwo;
System.out.print("make reverse after sum:- " + reverseSum);
}
}
Output:- make reverse after sum:- 975