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: Help With Multidimensional Arrays

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help With Multidimensional Arrays

    Hello Guys, Here I am again with another question. I have been having trouble trying to create and initialize arrays. I need to create a multidimensional array and have tried everything but always got hundreds of error messages. Please can you give me some hints on this? Here is the example I am trying to create:

    private String currData[] [] = new String [3] [5];
    currData [0] [0] = {" Dollars"};
    currData [0] [1] = {" Euros"};
    currData [0] [2] = {" Reais"};
    currData [0] [3] = new String " Swiss Francs";
    currData [0] [4] = new String{" Pounds"};
    currData [1] [0] = " Cents";
    currData [1] [1] = " Cents";
    currData [1] [2] = " Centavos";
    currData [1] [3] = " Cents";
    currData [1] [4] = " Pence";
    currData [2] [0] = " US$";
    currData [2] [1] = " "€";
    currData [2] [2] = " RS$";
    currData [2] [3] = " CHF";
    currData [2] [4] = " £";
    As you can see, I have tried several ways and it never compiles.
    Thanks for any help.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help With Multidimensional Arrays

    it never compiles.
    When you get errors, you should copy the full text of the error message and paste it here.
    Without the error message we may be guessing.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With Multidimensional Arrays

    I am using Javac to compile and cannot copy and paste from Command Prompt. The case is: If a create and initialize the array inside a class just for it, it works fine but if I try to initialize the array together with other variables, it does not work. It is so strange.

    --- Update ---

    For example:
    String currData[][] = new String [3][5];
    currData[0][0] = " Dollars";

    The second statement causes 7 errors: For example: "]" Expected, ";" Expected, Illegal start of type and so on.

    Any idea anyone? Thanks a lot.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Help With Multidimensional Arrays

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

    What errors do you get with the 2 lines in post #3?

    Where are those lines located in the source? The second line needs to be in a method.
    If you don't understand my answer, don't ignore it, ask a question.

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

    tristannvk (December 20th, 2012)

  6. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help With Multidimensional Arrays

    Thanks a lot. I just found out that the second part have to be in a method. That's why it wasn't working. it is fine now, thank you.

Similar Threads

  1. Reading ints into a multidimensional array
    By mju516 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 11th, 2012, 02:45 PM
  2. [SOLVED] adding to a multidimensional array.
    By Scotty in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 27th, 2011, 10:09 AM
  3. multidimensional array 'advancing'?
    By kitube in forum Java Theory & Questions
    Replies: 5
    Last Post: January 25th, 2011, 02:23 PM
  4. Need help in multidimensional array
    By Stefan_Lam in forum Algorithms & Recursion
    Replies: 3
    Last Post: January 14th, 2010, 08:52 PM
  5. Looping through a multidimensional array
    By MysticDeath in forum Loops & Control Statements
    Replies: 2
    Last Post: October 11th, 2009, 05:41 PM