Monday, 5 January 2015

Java Program to find the Reverse Of a number


This is a simple java program which finds the reverse of a given number.

PROGRAM :
package codingcorner.in;

import java.util.Scanner;

public class Reverse {
 public static void main(String[] args) {
  int number, remainder, reverse = 0, num;
  Scanner scan = new Scanner(System.in);
  System.out.print("Enter a number :\t");
  number = scan.nextInt();
  scan.close();
  num = number;
  while (number != 0) {
   remainder = number % 10;
   reverse = reverse * 10 + remainder;
   number = number / 10;
  }
  System.out.println("Reverse of number " + num + " is : \t  " + reverse);
 }
}


OUTPUT :






No comments:

Post a Comment