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: Having a bit of trouble with an array

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Having a bit of trouble with an array

    int [] storeNumber = new int[10];

    for(int i = 0; i < 10; i++)
    userInput = JOptionPane.showInputDialog("Enter number:");
    storeNumber[i] = Integer.parseInt(userInput); (This line does not work, anyone know why? error: "i cannot be be resolved to a variable")

    if anyone can help I would really be thankful.


  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Having a bit of trouble with an array

    Your code looks like this (with proper indention and brackets):
    for(int i = 0; i < 10; i++) {
        userInput = JOptionPane.showInputDialog("Enter number:");
    }
    storeNumber[i] = Integer.parseInt(userInput);
    Now, think about this for a little while and maybe you will spot your error.

  3. The Following User Says Thank You to Cornix For This Useful Post:

    geovanniluna (July 16th, 2014)

  4. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Having a bit of trouble with an array

    Cornix is right.
    You excluded the userInput from being assigned to storeNumber by not placing it within the For loop

    for(int i = 0; i < 10; i++) {
        userInput = JOptionPane.showInputDialog("Enter Number:");
        storeNumber[i] = Integer.parseInt(userInput);
    }
    Last edited by Stum; July 16th, 2014 at 01:48 AM.

  5. The Following User Says Thank You to Stum For This Useful Post:

    geovanniluna (July 16th, 2014)

  6. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Having a bit of trouble with an array

    @geovanniluna: Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    Please post your code correctly per the above link.

  7. #5
    Junior Member
    Join Date
    Jul 2014
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Having a bit of trouble with an array

    Thank you guys, I'm such a dork!! Of course I'm missing the brackets.

Similar Threads

  1. Having a bit of trouble trying to loop my project.
    By Ancharius in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 17th, 2013, 10:04 AM
  2. How to read file into n-bit array
    By hkocak in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 20th, 2013, 01:55 PM
  3. [SOLVED] Merge two 1D array's into a new 1D array. Trouble appending last index
    By norske_lab in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 30th, 2012, 12:57 PM
  4. bit array and register problem
    By ryu2le in forum What's Wrong With My Code?
    Replies: 35
    Last Post: August 31st, 2011, 10:52 PM
  5. String and Bit Array conversion issues
    By GeekWarth in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 16th, 2011, 07:13 PM