Results 1 to 13 of 13
Thread: need help..
- 03-18-2011, 12:39 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 28
- Rep Power
- 0
- 03-18-2011, 12:49 PM #2
What is your exact requirement, charAt() will fetch character one by one
sanjeev,संजीव
- 03-18-2011, 01:36 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 28
- Rep Power
- 0
i want to fetch integer one by one.
eg: 1000110101
i want to fetch each integer one by one
- 03-18-2011, 10:58 PM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
There are two methods to go about this, one is to use modulus(%) and division(/) the other way would require turning the number 1000110101 into a string first.
- 03-19-2011, 01:16 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Out of sunde887s' suggestions, you've to select the best based on your requirements. Say that you are working with integers along the program, then you've to careful about converting into string and use of charAt(). Wise verse too.
- 03-19-2011, 03:40 AM #6
Member
- Join Date
- Feb 2011
- Posts
- 44
- Rep Power
- 0
int myInteger=10101011;
String myString=" ";
myString = Integer.toString(myInteger);
now excecute that function CharAt(myStinring)
and u will get the result :d
- 03-19-2011, 04:19 AM #7
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
There may be some more thinking as well, but not much. You can also make a number a string with the following statement.
Java Code:String myString = 10101101 + "";
- 03-19-2011, 05:07 AM #8
Or String.valueOf(int)
db
- 03-20-2011, 07:03 AM #9
Member
- Join Date
- Feb 2011
- Posts
- 28
- Rep Power
- 0
so the best solution is to turn those integers into string first?
is there any method or function that will make me able to fetch integer one-by-one?
cause if possible i want to make it stay as integer, don't want to convert.
- 03-20-2011, 07:20 AM #10
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
My original post gave you how to do it two ways, one was to use modulus(%) and division(/) and the other was conversion and then using charAt(), both ways are equally viable, however; the former will take some thinking on your part.
- 03-20-2011, 07:40 AM #11
Member
- Join Date
- Feb 2011
- Posts
- 28
- Rep Power
- 0
do you mind to show me an example on using the % and / ??
- 03-20-2011, 07:47 AM #12
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
It's hard to give an example that doesn't give you the answer. If you have the number 107, what would give you 7?
107 % x = 7
- 03-23-2011, 08:36 AM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Modulus and division cannot done the trick with numbers which don't have 1s and 0s.


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks