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

Thread: arrays ... what am i doing wrong?

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    11
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default arrays ... what am i doing wrong?

    i was trying to create a new array:
    int[][] location;
    but for some reason the moment i try to call that array it gives me an error:
    int[][] location;
    location = new int[10][2];
    error: "syntax error on token ";" , { expected after token"
    this error is given for the declaration of the array
    any one know what i am doing wrong?


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    563
    My Mood
    Sleepy
    Thanks
    9
    Thanked 82 Times in 76 Posts

    Default Re: arrays ... what am i doing wrong?

    Your braces are likely to be messed or you are trying to initialize your array outside of a method. Hard to tell without seeing your code. When you post code use code tags: [code] your code [/code]

  3. #3
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: arrays ... what am i doing wrong?

    Please post any relevant code and the full text of error messages with your question.

  4. #4
    Junior Member
    Join Date
    Apr 2013
    Posts
    11
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: arrays ... what am i doing wrong?

    well this is basically the whole code .... and the error is given the scond i try to allocate the memory of the array
    the error is given for the declarations.
    public class AI{
    		int max,min;
    		int[][] location;
    		int[] best;		
    		location = new int[10][2];
    		best = new int[4];
    }

  5. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default Re: arrays ... what am i doing wrong?

    You can not use an "assignment" statement outside an executable block of code.

    You are just within the class body. You can declare variables, or initialize variables, but not have assignment to an existing variable.

    int[][] location = new int[10][2]; would be the simple way to do what you are trying to do.

    To use int[][] location; and location = new int [10][2]; the location = ... would have to be inside a method (like main).

  6. The Following User Says Thank You to jps For This Useful Post:

    crazyboy5012 (April 23rd, 2013)

  7. #6
    Junior Member
    Join Date
    Apr 2013
    Posts
    11
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: arrays ... what am i doing wrong?

    oh ok ... thx !

Similar Threads

  1. Help with Arrays!
    By le pencil in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 12th, 2013, 12:05 PM
  2. Help with Arrays
    By djhunt90 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 16th, 2012, 02:27 PM
  3. Help with arrays
    By mike2452 in forum Collections and Generics
    Replies: 6
    Last Post: August 6th, 2011, 12:15 PM
  4. Need Help with Arrays
    By zennbang in forum Object Oriented Programming
    Replies: 3
    Last Post: July 31st, 2011, 06:41 AM
  5. arrays
    By dwamalwa in forum Java Theory & Questions
    Replies: 4
    Last Post: November 27th, 2010, 12:44 AM