Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with array

Status
Not open for further replies.

skarosi

Programmer
Jan 25, 2004
140
GR
Hi all,
I have to make a programm that uses an array, i have declared the array as a global variable, but the problem is that the size of the array is been inserted by the user later on, so i cant set the size of it on the declaration.
What can i do,apparently the size of it is not been updated when the value changes.
Thanks
 
You can't change the size as you go. When you declare it declare it as: <type> myArray[];
then when you know the size that you want it then create it: myArray[] = new array[size];
 
and this will still keep it global variable right?
ok i will try this
 
it seems that this doesnt work,
i got it like this:
global variable
public int[][] G;
and in the method
G[][] = new array[rows][cols];
and i got these errors:
C:\...Gallager2.java:150: not a statement
G[][] = new array[rows][cols];
^
C:\...Gallager2.java:150: ';' expected
G[][] = new array[rows][cols];
^
any ideas?
 
Code:
public int[][] someIntArray;

someIntArray = new int[5][4];

Also, naming a variable "G" is not very good style - a variable name should be descriptive.

--------------------------------------------------
Free Database Connection Pooling Software
 
this one worked sedj, cheers.
also G is the name of the array that the documentation uses.so i just had to use this name.
thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top