Results 21 to 25 of 25
- 11-08-2010, 01:41 AM #21
Member
- Join Date
- Oct 2010
- Posts
- 26
- Rep Power
- 0
- 11-08-2010, 01:44 AM #22
Member
- Join Date
- Oct 2010
- Posts
- 26
- Rep Power
- 0
what ever input is input.... i want reversed. doesn't matter what the integer is... 1000 reverse is 0001
9876543210 reversed would be 0123456789...
- 11-08-2010, 01:50 AM #23
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
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.
- 11-08-2010, 02:06 AM #24
Member
- Join Date
- Oct 2010
- Posts
- 26
- Rep Power
- 0
oh okay i understand now...so int class can not have 0's in front.
i got it... thanks for the help
- 11-09-2010, 02:59 PM #25
Member
- Join Date
- Nov 2010
- Posts
- 1
- Rep Power
- 0
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...
Similar Threads
-
how to input unspecified number if ints with a scanner
By ftrengnr in forum New To JavaReplies: 2Last Post: 09-14-2010, 01:24 AM -
Changing Scanner input type
By mlad in forum New To JavaReplies: 13Last Post: 03-18-2010, 04:22 PM -
problem with Scanner in Getting users input
By kliane in forum New To JavaReplies: 8Last Post: 01-17-2010, 04:37 PM -
Taking args consisting of a scanner input
By Implode in forum New To JavaReplies: 1Last Post: 09-27-2009, 09:16 PM -
Scanner input problem
By slayer_azure in forum New To JavaReplies: 3Last Post: 05-26-2008, 10:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks