Program to Reverse Number in Java

Program to Reverse Number in Java

Here you will figure out how to reverse a number in java in java with a program model.

For instance, the given number is 1478 then its turn around will be 8741.

package com;
 
import java.util.Scanner;
 
class Reverse
{
	public static void main(String...s)
	{
		int n,rev=0,i;
		Scanner sc = new Scanner(System.in);
 
		System.out.println("Enter any number: ");
		n = sc.nextInt();
		
		while(n!=0)
		{
			i=n%10;
			rev=(rev*10)+i;
			n/=10;
		}
		
		System.out.println("\nReverse = "+rev);
		sc.close();
	}
}

Output

Enter any number:
4567

Reverse = 7654

Recent Posts

error: Alert: Content is protected!!