Results 1 to 2 of 2
  1. #1
    joeyalf is offline Member
    Join Date
    Dec 2011
    Rep Power

    Default Reading input and storing into array

    I am having trouble doing so. I am required to have the user enter integers seperated by commas and I need to then store only the integers into an array. I am new to java. I tried the skip method but I don;t know how it works. Here is what I have so far. Thanks in advance!

    int numbers;
    Scanner keyboard = new Scanner(;

    System.out.println("Enter your numbers separated by commas below:");
    numbers = keyboard.nextInt();

    int arrayname[] = new int[numbers];

    for (int i = 0; i < numbers; i++)
    arrayname[i] = keyboard.nextInt();

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Rep Power

    Default Re: Reading input and storing into array

    See the StringTokenizer class and the String.split method - if you read the user entered String in its entirety you can use these to split up the string based upon comma's

Similar Threads

  1. Need help with array and storing input
    By Bewitched1 in forum New To Java
    Replies: 8
    Last Post: 07-24-2010, 05:16 PM
  2. Reading a txt file and then storing it in a 2d array
    By blkshp1990 in forum New To Java
    Replies: 2
    Last Post: 11-05-2009, 12:31 AM
  3. Replies: 3
    Last Post: 10-28-2009, 01:45 AM
  4. Replies: 4
    Last Post: 03-12-2009, 11:25 AM
  5. Reading input file into an array
    By littlefire in forum New To Java
    Replies: 6
    Last Post: 10-18-2008, 11:51 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