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

    Default how to reverse some input from scanner

    i want to ask a user to input some integers:

    1234

    then i want to reverse the order and output like this:

    4321

    how do i go about doing this? and how do i go about solving a problem like this without asking people how to figure it out?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    By looking in the String API. There you'll find methods that will help you solve this problem.

    Please let us know how this turns out. Luck!

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

    Default

    ok i found it... at first i just ctrl f (reverse) and it didn't find anything... then i clicked integer and found it under there.. thanks

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by moncur View Post
    i want to ask a user to input some integers:

    1234

    then i want to reverse the order and output like this:

    4321

    how do i go about doing this? and how do i go about solving a problem like this without asking people how to figure it out?
    Before you go ask questions to someone else, ask yourself the question how you want to output the reverse of, say, 1230 or 1200 or 1000.

    kind regards,

    Jos

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by moncur View Post
    ok i found it... at first i just ctrl f (reverse) and it didn't find anything... then i clicked integer and found it under there.. thanks
    Hm, I'm not sure what this means. If you get stuck please clarify. Best of luck!

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

    Default

    Quote Originally Posted by JosAH View Post
    Before you go ask questions to someone else, ask yourself the question how you want to output the reverse of, say, 1230 or 1200 or 1000.

    kind regards,

    Jos
    i did...

    input as int: 1234
    output as int: 4321

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

    Default

    Quote Originally Posted by Fubarable View Post
    Hm, I'm not sure what this means. If you get stuck please clarify. Best of luck!
    means... when i was on the API website... i tried to find reverse on main page... and nothing came up... then under integer class i found the reverse...

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by moncur View Post
    i did...

    input as int: 1234
    output as int: 4321
    And what about 1230 or 1200 or 1000? Should they show up a 321, 21 and 1 or as 0321, 0021 and 0001?

    kind regards,

    Jos

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by moncur View Post
    means... when i was on the API website... i tried to find reverse on main page... and nothing came up... then under integer class i found the reverse...
    I second JosAH's recommendation as your current code will probably fail with his tests.

    I should have been more specific. Check out the String API, not the main page, and don't look for a reverse method, but rather methods that allow you to loop through your String in a for loop and get char at specific locations.

    Luck!

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

    Default

    Write a method reverse that accepts an int number and returns an int with the digits in reverse order. For example,
    int revNum = reverse( 1234 ); // revNum has a value of 4321

    is this better?

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by moncur View Post
    Write a method reverse that accepts an int number and returns an int with the digits in reverse order. For example,
    int revNum = reverse( 1234 ); // revNum has a value of 4321

    is this better?
    ?
    Your statement above simply states the requirements. Again, have you tested your code with JosAH's test values? What happens when you do?

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    We need a dentist here, a proctologist just doesn't cut it ;)

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

    Default

    ok new question... how do you get the length of input from a scanner input that is only integers?


    example:

    user enters: 1234

    how do i get the length of 1234?

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

    Default

    You still haven't answered the question several folks have been askin' you! Where's the friggin' dentist when you need him??

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

    Default

    cause i dont' know what the fuck you guys want from me...

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

    Default

    Quote Originally Posted by moncur View Post
    cause i dont' know what the **** you guys want from me...
    Then maybe you should say so rather than ignoring the question. Most here assume that you have solved your problem using method from integer. They're simply asking you to test your current code with the numbers that JosAH provided and that you report here on the result of this test. Was that so f***in hard to figure out?

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

    Default

    i didn't ignore the question... i said what i wanted numerous times....

    get an integer
    reverse the integer

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

    Default

    435 would be 534


    are we on the same page now?

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

    Default

    4587 would be 7854

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

    Default

    Quote Originally Posted by JosAH View Post
    And what about 1230 or 1200 or 1000? Should they show up a 321, 21 and 1 or as 0321, 0021 and 0001?

    kind regards,

    Jos
    sigh,.... what about 1230, 1200, or 1000?

Page 1 of 2 12 LastLast

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
  •