Here you will learn how to reverse number in java with a program example.
For example given number is 1478 then its reverse will be 8741.
Program to Reverse Number in Java
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