Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25
  1. #21
    moncur is offline Member
    Join Date
    Oct 2010
    Posts
    26
    Rep Power
    0

  2. #22
    moncur is offline Member
    Join Date
    Oct 2010
    Posts
    26
    Rep Power
    0

    Default

    what ever input is input.... i want reversed. doesn't matter what the integer is... 1000 reverse is 0001

    9876543210 reversed would be 0123456789...

  3. #23
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    But does the method show the leading 000? For instance if you pass 1000 to your method, do you get 0001 returned or do you get 1? If your code was based on a method from the Integer class, then it will return an int, and for int there's no such thing as 0001, there's just 1. If you want the leading 0's, then you're going to have to use String methods, the easiest being to use a StringBuilder object, initialize it with your String, call reverse() on it, and then get the String form it via its toString() method.

    If this is a class assignment though, and you require the leading 0's, then you'll probably need to use some of the methods in the String class such as charAt(int i) to help you iterate through the String with a for loop.

    Up to you and depends on your requirements.

  4. #24
    moncur is offline Member
    Join Date
    Oct 2010
    Posts
    26
    Rep Power
    0

    Default

    oh okay i understand now...so int class can not have 0's in front.

    i got it... thanks for the help

  5. #25
    larryf is offline Member
    Join Date
    Nov 2010
    Posts
    1
    Rep Power
    0

    Default

    It is a test question at codility.com , I wonder whether OP is taking a test at Codility now :-) I took this test, they ask to return an integer (and they pass integer as input), so IMHO it is best to solve it in pure arithmetic without going back and forth between ints and strings. If this is the OP's question's context, then your question of 0012 vs. 12 does not apply... but it OP is really taking a test, then this question should not show up here...

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 2
    Last Post: 09-14-2010, 01:24 AM
  2. Changing Scanner input type
    By mlad in forum New To Java
    Replies: 13
    Last Post: 03-18-2010, 04:22 PM
  3. problem with Scanner in Getting users input
    By kliane in forum New To Java
    Replies: 8
    Last Post: 01-17-2010, 04:37 PM
  4. Taking args consisting of a scanner input
    By Implode in forum New To Java
    Replies: 1
    Last Post: 09-27-2009, 09:16 PM
  5. Scanner input problem
    By slayer_azure in forum New To Java
    Replies: 3
    Last Post: 05-26-2008, 10:49 PM

Posting Permissions

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