Results 1 to 3 of 3
- 07-24-2012, 01:57 AM #1
Member
- Join Date
- Jul 2012
- Posts
- 1
- Rep Power
- 0
I want to print a Decimal Number in reverse.
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?
PHP 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 } }
- 07-24-2012, 10:55 AM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
- 07-24-2012, 03:38 PM #3
Similar Threads
-
Easy Question! Print out file, count number of lines, number of spaces w/ Scanner
By LogicalOutlier in forum New To JavaReplies: 8Last Post: 01-21-2012, 01:14 AM -
Help decimal number { float or double??} HELP!
By mackiver in forum New To JavaReplies: 3Last Post: 10-24-2011, 05:06 AM -
Reverse Number guessing game
By rarman555 in forum New To JavaReplies: 6Last Post: 04-24-2011, 01:46 AM -
truncate a decimal number ?
By hacikho in forum New To JavaReplies: 5Last Post: 10-13-2010, 08:58 PM -
Converting whole number into decimal
By jim01 in forum New To JavaReplies: 2Last Post: 09-23-2010, 07:58 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks