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 3 of 3

Thread: Split a String into Ints

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Split a String into Ints

    Hello,

    So I'm working on a project, and it requires me to split up an integer into each of it's numbers so I can create a base 10 polynomial representation of the number. The problem is, I'm not sure quite how to do it. I figure I can convert the int into a string, and then I want to split the string with the split method, but I run into two problems. First, I feel there must be an easier way to do this. Second, if there isn't, then I'm not sure how to split it up. I tried string.split("/d"), but I'm getting an error message.

    I guess my question is, what's the most efficient way to approach this.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Split a String into Ints

    The / and % operators are useful in getting the separate digits out of an int value.
    13 / 10 = 1
    13 % 10 = 3
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Split a String into Ints

    Man, as a mathematician I should totally have thought of that. I need to work on going between comp sci and math mode. Thanks!

Similar Threads

  1. Split a string into individual characters
    By djl1990 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 6th, 2012, 03:55 PM
  2. Replies: 3
    Last Post: October 26th, 2012, 02:19 PM
  3. Parsing many Ints from a user input String.
    By helpmeplease111 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 7th, 2011, 08:41 PM
  4. Conversion from multiple ints to single string
    By surfbumb in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 12th, 2011, 10:08 PM
  5. adding multiple ints into a string
    By straw in forum Java Theory & Questions
    Replies: 1
    Last Post: March 18th, 2010, 06:02 PM