Showing posts with label reverse a number in java version 2. Show all posts
Showing posts with label reverse a number in java version 2. Show all posts

Sunday, June 28, 2015

Reverse a Number in Java Version 2

A simple program that will ask the user to enter a number and then it will reverse the arrangement of number given by the user.The code is very simple but it uses already the concepts of object oriented programming.

I hope you will find my work  useful in a sense the logic of programming is also applied in this simple program.

If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

import java.util.Scanner;


class reverse_number {
    public int reverse_given_number(int number)
    {
         
        int reverse = 0;
        while(number != 0){
            reverse = (reverse*10)+(number%10);
            number = number/10;
        }
        return reverse;
    }

public static void main(String args[]) {
  Scanner scan = new Scanner(System.in);
   char a;
do
    {
  // creating of value object
  
   reverse_number value = new reverse_number();
      
  System.out.println();
  System.out.println("===== REVERSE A NUMBER =====");
  System.out.println();
  System.out.print("Enter a Number :  ");
  int number_value =   scan.nextInt();
  
  System.out.println();

  System.out.print("The given number is " + number_value + 
  " it's reverse order will be " +value.reverse_given_number(number_value)+ ".");
    System.out.println("\n\n");
    System.out.print("Do you Want To Continue (Y/N) :=> ");
    a=scan.next().charAt(0);

   } while(a=='Y'|| a=='y');
          System.out.println("\n");
          System.out.println("\t ===== END OF PROGRAM ======");
         System.out.println("\n");
 }
  
   } // End of Program