Results 1 to 4 of 4
Thread: select a digit in a number
- 12-09-2010, 08:23 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
- 12-09-2010, 08:30 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
String.valueOf(1234) and then charAt or toCharArray and array[2] or with mathematics a/=10 + a%10 or the scanner class or ...many many more :)
- 12-09-2010, 09:03 PM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
I want to select a digit in a number. for example select 3 in 1234.
Are you trying to find the character (digit) given its index (eRaaaa's examples)? Or trying to find the index given the digit? For the latter there is the String method indexOf().
-------------
It's worth nothing that these sorts of problem are intrinsically about strings (/numerals/string representations of numeric quantities) rather than numbers. The / and % approach, as given, depends on the digit being sought in a base 10 representation: but, of course, Java ints (like numeric quantities generally) have no base.
- 12-12-2010, 10:47 AM #4
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
digit spacing
By puk284 in forum New To JavaReplies: 3Last Post: 06-09-2009, 02:49 PM -
Locating a digit within a string
By ScentOfAWookie in forum New To JavaReplies: 8Last Post: 03-27-2009, 05:23 PM -
How to retain value in struts 2 using <s:select></s:select> tag
By SaiPrasad@Sella in forum Web FrameworksReplies: 0Last Post: 02-09-2009, 07:23 AM -
Java newb Q: 8-digit id
By 1111FM in forum New To JavaReplies: 2Last Post: 09-29-2008, 02:37 PM -
convert getValue result in a 4 digit number
By roseline43 in forum New To JavaReplies: 0Last Post: 09-02-2008, 08:44 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks