09 April 2012

Reverse a Number and display it




public class ReverseNumber {
public static void main(String[] args) {
int number = 1234;
int reversedNumber = 0;
int temp = 0;
while(number > 0){
temp = number%10;
reversedNumber = reversedNumber * 10 + temp;
number = number/10;
}
System.out.println("Reversed Number is: " + reversedNumber);
}
}
/*
Output of this Number Reverse program would be
Reversed Number is: 4321
*/

0 comments:

Post a Comment

Related Posts with Thumbnails

Popular Posts

 
;