I want to print a Decimal Number in reverse.

Hi :(hi):, I am new to Java, and I am suppose to implement a recursive method that writes the digits of a DECIMAL number in opposite/reverse order. The number is positive so you do not need to worry about negative signs etc.

What I have is below...I know it works for Integer numbers, but I do not think it will work for decimals.. I was helped out earlier, and was told, that the 10 is a "good number" to use for dividing the input number..I am unsure why?:s:

Code:

`void reverseDigits(int number){ `

if(number >= 0) // Make sure we have a positive number

{

if(number < 10)

System.out.print(number);

else

{

System.out.print(number % 10); // This prints the right most number first (or in position 1)

reverseDigits(number / 10); // The remainder of the digits are to follow

}

}

Re: I want to print a Decimal Number in reverse.

Quote:

Originally Posted by

**LazerJet** I know it works for Integer numbers, but I do not think it will work for decimals

can`t follow you ...:(think):

Re: I want to print a Decimal Number in reverse.

Quick question... have you tried it out with a double or a float value to see if it works with decimals?