Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to parse an multidigit in an sequence of particular digits

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to parse an multidigit in an sequence of particular digits

    For example we have a number 1709. How to define every digit of the number. Should we cast type to string. Then to parse it with toCharArray method. And use the indexes to have an access to char array of this particular digit also with reversal type casting. For example: int number=1709; char [] array=number.toCharArray(); int b=9; int suma=b+(int)array[0]; System.out.print(suma); is it correct at least in principle or we should use other way?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to parse an multidigit in an sequence of particular digits

    is it correct
    What have you tried? What happened? The compiler will tell you if the syntax is correct.

    If you have questions about java code, post the code and be sure to wrap the code in code tags.

    See the Integer class has a method for creating a String from an int value.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Oct 2013
    Location
    Saint-Petersburg, Russia
    Posts
    33
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Default Re: How to parse an multidigit in an sequence of particular digits

    You'd better explain why you need it.

    If this is a kind of school task, then you are really supposed to divide number by 10 several times keeping remainders.

    Here is a short explanation:
    Wiki: Number to Digits - CodeAbbey

    Though for industrial usage of course you can convert number to string and get bytes of it. Especially if you are not interested in numeric values of digits themselves.

  4. #4
    Junior Member
    Join Date
    Jun 2013
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to parse an multidigit in an sequence of particular digits

    No I need numeric values of this digits. So I do not understand why to convert int number to String and than get bytes of it. As I know: when I use string[0] it doesnt mean that is the first letter (digit)-but the first string in array of string. Or am I not correct? I need access to the symbols of numbers so as I understand that I need a char array: char [] num={1,7,0,9}. Than I need to know if the first digit is dividable to 2, or all digits. Maybe be authors of such test tasks precepitated the using of "divide by 10" but if we would need to know the divideness of the second or third digit it should be more difficutlu to use this method. /So this I need for the test in software firm that engaged in industrial programming. So I would be gratefull for the help. What method Of String class I need, is it possible to use toCharArray method or just divide by 10?

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to parse an multidigit in an sequence of particular digits

    What have you tried? Post the code you are having problems with.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: October 25th, 2013, 06:31 AM
  2. sum of digits
    By snarayana.murthy86 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 18th, 2013, 02:40 PM
  3. Calculating Pi to more digits?
    By sci4me in forum Java Theory & Questions
    Replies: 5
    Last Post: May 23rd, 2013, 01:41 PM
  4. [SOLVED] 1, 4, 9, 16 sequence
    By mattisvan in forum Loops & Control Statements
    Replies: 4
    Last Post: March 15th, 2013, 07:18 AM
  5. All Digits only
    By kram in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 28th, 2011, 03:16 PM