reverse a number using mathematical operations in java

Solutions on MaxInterview for reverse a number using mathematical operations in java by the best coders in the world

showing results for - "reverse a number using mathematical operations in java"
Leana
05 Mar 2019
1//continue to loop until  a value is equal to 0
2
3public class ReverseNum{
4  
5  public static void main(String[] args {
6  
7  int a = 543;
8  int reverse = 0;
9  
10 while(a!=0){ //itera the process
11 
12 int digit = a%10; //isolate the last digit number
13 
14 reverse = digit + (reverse*10); //append last digit to reverse
15 a=a/10; // remove the last digit from number
16   } 
17   System.out.println(reverse);
18   
19     } }