This is the fourth solution to find the reverse of an integer value, by using the core logic of forming the number in the reverse order.
import java.util.Scanner;
public class ReverseOfInt {
public static void main(String[] args) {
// TODO Auto-generated method stub
@SuppressWarnings("resource")
Scanner intInp= new Scanner(System.in);
//Input an Integer
System.out.println("Enter an Integer=");
int numValue=intInp.nextInt();
System.out.println("The integer is="+numValue);
int numBackup = numValue, revNum=0, rem;
while (numValue!=0) {
rem=numValue%10;
revNum=revNum*10+rem;
numValue=numValue/10;
}
System.out.println("The reverse of number="+numBackup+" is="+revNum);
}
}
Output:
Enter an Integer=
361
The integer is=361
The reverse of num=361 is=163

Leave a comment