top of page
Writer's pictureSatyam Gupta

Reverse of a Number in JAVA

Reverse of a Number


Program to display reverse of a number

Example : Original Number : 423

                 Reverse Number : 234


Algorithm :-

  • Input a number from user

  • store a copy of entered number in another variable

  • use while loop for reversing the number

  • Print the original number as well as Reverse number


Program :-


import java.io.*; import java.util.*; class Reverse {     public static void main(String args[])     {         Scanner in= new Scanner(System.in);         int n,p,rev,s=0;         System.out.println("Enter No.");         n= in.nextInt(); // Input number from user         p=n; // store the entered number in "p" variable         while(n>0)         {             rev=n%10; // extract last digit of the number             s=s*10+rev; // store the digit last digit             n=n/10; // extract all digit except the last         }         System.out.println("Original Number : "+p);         System.out.println("Reverse Number : "+s);     } // end of main method } // end of class


 

Note : The program is written in the easiest way possible so try understand it. If you face any problem in understanding this program than feel free to contact/comment. All the Best :)

Keep Learning :)

16 views0 comments

Recent Posts

See All

Comments


Post: Blog2_Post
bottom of page