Wednesday, 20 May 2015

Program: Write a program to reverse a number.

Below program shows how to reverse a number using numeric operations.

package in.blogspot.java2bigdata;
 
public class NumberReverse {
 
    public int reverseNumber(int number){
         
        int reverse = 0;
        while(number != 0){
            reverse = (reverse*10)+(number%10);
            number = number/10;
        }
        return reverse;
    }
     
    public static void main(String a[]){
        NumberReverse reverseNum = new NumberReverse();
        System.out.println("Result: "+reverseNum .reverseNumber(212015));
    }
}


// Output:
//Result:510212

Prgram:Factorial of a number.
Program:The leap year rule.

No comments:

Post a Comment