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("Reverse = "+rev); sc.close(); } }
Enter any number: 1234 Reverse = 4321
For example if given number is 1234 then its reverse will be 4321.