Here is a Java Program to Reverse the Given Number
Output of Above Java Program
Enter the number:
12345
The reverse number is 54321.
import java.io.*; class reverse{ public static void main(String [] args) { try { BufferedReader obc=new BufferedReader (new InputStreamReader(System.in)); int n,r; int rev=0; System.out.println("Enter the number: "); n=Integer.parseInt(obc.readLine()); while(n>0) { r=n%10; rev=rev*10+r; n=n/10; } System.out.println("The reverse number is "+rev+"."); } catch(IOException e) { System.out.println("Wrong number entered."); } } }
Output of Above Java Program
Enter the number:
12345
The reverse number is 54321.