Reverse number in Java

 import java.util.Scanner;  
 public class ReverseNumber{  
      public static void main(String [] args){  
      Scanner sc=new Scanner(System.in);  
      System.out.println("Enter the number: ");  
      int reverse=0;  
      int remainder=0;  
      int number=sc.nextInt();  
      do{  
           remainder=number%10;  
           reverse=remainder+(reverse*10);  
           number=number/10;  
      }while(number>0);  
      System.out.println(reverse);  
      sc.close();  
 }  
 }  

Output:
Enter the number: 1234
4321.

Comments

Popular posts from this blog

Reasoning-Number Series

Reasoning-Letter Series

Profit and Loss