Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By eRaaaa

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

  1. #1
    LazerJet is offline Member
    Join Date
    Jul 2012
    Posts
    1
    Rep Power
    0

    Default 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
    } 
    }

  2. #2
    eRaaaa is online now Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

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

    Quote Originally Posted by LazerJet View Post
    I know it works for Integer numbers, but I do not think it will work for decimals
    can`t follow you ...
    Rameshwar Soni likes this.

  3. #3
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default 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?
    My API:
    Java Code:
    cat > a.out || cat > main.class

Similar Threads

  1. Replies: 8
    Last Post: 01-21-2012, 01:14 AM
  2. Help decimal number { float or double??} HELP!
    By mackiver in forum New To Java
    Replies: 3
    Last Post: 10-24-2011, 05:06 AM
  3. Reverse Number guessing game
    By rarman555 in forum New To Java
    Replies: 6
    Last Post: 04-24-2011, 01:46 AM
  4. truncate a decimal number ?
    By hacikho in forum New To Java
    Replies: 5
    Last Post: 10-13-2010, 08:58 PM
  5. Converting whole number into decimal
    By jim01 in forum New To Java
    Replies: 2
    Last Post: 09-23-2010, 07:58 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •