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