How to Reverse a Given Number

How to Reverse a Given Number
SOURCE : ReverseNumber.java

public class ReverseNumber {

public static int number(int num) {
int rervse = 0;
while (num != 0) {

rervse = (rervse * 10) + (num % 10);
num = num / 10;

}

return rervse;
}

public static void main(String[] args) {

int n = 12345;

System.out.println("reversed number is : " + number(n));

}

}


INPUT

int n = 12345;



OUTPUT

reversed number is:54321






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment