Results 1 to 13 of 13

Thread: need help..

  1. #1
    stegano is offline Member
    Join Date
    Feb 2011
    Posts
    28
    Rep Power
    0

    Default need help..

    charAt() function will fetch each character one by one. How about integer?
    is there any function that works like that? or should i use charAt() too??

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    What is your exact requirement, charAt() will fetch character one by one
    sanjeev,संजीव

  3. #3
    stegano is offline Member
    Join Date
    Feb 2011
    Posts
    28
    Rep Power
    0

    Default

    i want to fetch integer one by one.

    eg: 1000110101

    i want to fetch each integer one by one

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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.

  6. #6
    lulzim is offline Member
    Join Date
    Feb 2011
    Posts
    44
    Rep Power
    0

    Default

    int myInteger=10101011;
    String myString=" ";
    myString = Integer.toString(myInteger);

    now excecute that function CharAt(myStinring)
    and u will get the result :d

  7. #7
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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 + "";

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

    Default

    Or String.valueOf(int)

    db

  9. #9
    stegano is offline Member
    Join Date
    Feb 2011
    Posts
    28
    Rep Power
    0

    Default

    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.

  10. #10
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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.

  11. #11
    stegano is offline Member
    Join Date
    Feb 2011
    Posts
    28
    Rep Power
    0

    Default

    do you mind to show me an example on using the % and / ??

  12. #12
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Posting Permissions

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