Results 1 to 5 of 5
  1. #1
    prof.deedee is offline Member
    Join Date
    Oct 2009
    Posts
    36
    Rep Power
    0

    Default change string to array of integer

    Hi
    in my code I read user input as string then I want to change it to array of integer ...HOW???
    for example:

    BufferedReader in=new BufferedReader( new InputStreamReader(System.in));
    string input=in.readLine();

    and here input =45678

    now, how can I save these numbers in array of integer??:rolleyes:

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Split the input into a String array, create an int array of the same length and use Integer.parseInt to fill the int array.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

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

    Default

    Loop through the string by selecting each character and do conversion. Before that initialize and array on int in the same size of string.

  4. #4
    prof.deedee is offline Member
    Join Date
    Oct 2009
    Posts
    36
    Rep Power
    0

    Default

    Thank u it works

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

Similar Threads

  1. String to Integer Conversion in JSP
    By vinikz in forum New To Java
    Replies: 8
    Last Post: 11-10-2010, 03:45 PM
  2. check if String is an integer?
    By McChill in forum New To Java
    Replies: 5
    Last Post: 05-02-2009, 08:51 PM
  3. Replies: 1
    Last Post: 03-31-2009, 07:40 AM
  4. Integer to String
    By zervine in forum Forum Lobby
    Replies: 3
    Last Post: 09-12-2008, 01:07 PM
  5. String to Integer conversion
    By eva in forum New To Java
    Replies: 2
    Last Post: 12-17-2007, 04:59 PM

Posting Permissions

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