Advertisement
shawonrog

reverse number

Feb 19th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.48 KB | None | 0 0
  1. package javalab;
  2.  
  3.  
  4.  
  5. import java.util.Scanner;
  6.  
  7. class Javalab
  8. {
  9.    public static void main(String args[])
  10.    {
  11.       int n, reverse = 0;
  12.  
  13.       System.out.println("Enter a number to reverse");
  14.       Scanner in = new Scanner(System.in);
  15.       n = in.nextInt();
  16.  
  17.       while(n != 0)
  18.       {
  19.           reverse = reverse * 10;
  20.           reverse = reverse + n%10;
  21.           n = n/10;
  22.       }
  23.  
  24.       System.out.println("Reverse of the number is " + reverse);
  25.    }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement