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

Thread: Help with arrays

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help with arrays

    Hi there, I am fairly new to Java and i need your help! I do not understand what is going on, im trying to make an array and on one of the lines it says " 'i' cannot be resolved in the variable ".

    Here is my code:
    public class Arrays {
    	public static void main(String[] args) {
     
    		int value = 7;
     
    		int[] values;
    		values = new int [3];
     
    		System.out.println(values[0]);
     
    		values[0] = 10;
    		values[1] = 20;
    		values[2] = 30;
     
    		System.out.println(values[0]);
    		System.out.println(values[1]);
    		System.out.println(values[2]);
     
    		for(int i = 0; i < values.length; i++); {
    			System.out.println(values[i]);
    		}
    	}
    }

    im getting the error with the i in this line of code System.out.println(values[i]);

    Thanks in advance!

    also i am using a program called Eclipse - Kepler


  2. #2
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default Re: Help with arrays

    Your problem lies here.

    for(int i = 0; i < values.length; i++); {

    Look very carefully.

    Might I say, well done on posting correctly the first time too.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with arrays

    Thanks! What i did was i took int out of for and put it in its own row like this:
    int i=0;
    for(i=0; i<values.length; i++); {
    It worked, but is that what i should do in the future?

    Nevermind, what i did is now canceling out int value = 7;

    i really suck at this.

  4. #4
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default Re: Help with arrays

    No, that's not it. It's a syntax error in your original code. You have incorrectly placed a semicolon after the closing parentheses in your 'for loop'. Remember that a semicolon indicates the end of a statement.

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with arrays

    OH WOW I'm sorry about that, this is like my 3rd day into Java, i still dont really know where everything goes. Thanks dude!

  6. #6
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default Re: Help with arrays

    That's cool, you'll probably do more stuff like this and stare at it for ages. Your IDE Eclipse is good at pointing out stuff most of the time. Now you're aware of it, you'll be very vigilant.

    Stick at it, it's lots of fun and rewarding.

  7. #7
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Help with arrays

    Quote Originally Posted by Kewish View Post
    It's a syntax error in your original code.
    It's a semantic error. If it were a syntax error the code would not compile.
    Improving the world one idiot at a time!

  8. #8
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default

    Yes of course cheers Junky

Similar Threads

  1. Arrays
    By LeeDD in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 23rd, 2013, 09:10 PM
  2. Need help with arrays
    By Burnett98 in forum What's Wrong With My Code?
    Replies: 27
    Last Post: January 23rd, 2013, 05:23 PM
  3. Need help using Arrays!
    By asb23698 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 4th, 2012, 06:47 PM
  4. Arrays
    By av8 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 25th, 2011, 01:21 PM
  5. 3 Arrays
    By D3158 in forum Collections and Generics
    Replies: 27
    Last Post: June 16th, 2011, 11:10 AM