To reverse the number , we repeatedly extract the last digit of the number by using (%10) and add it to the new number let the variable name reverse. we then remove the last number from the original number using (/10). This process continues till the original number becomes zero. At last the reverse variable stores the reverse of the number.
#logic
int n=sc.nextInt();
int rev=0;
while(n!=0)
{
int rem=n%10;
rev=rev*10+rem;
n=n/10;
}