Computing.Net > Forums > Programming > Java - creating multiple arrays.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Java - creating multiple arrays.

Reply to Message Icon

Name: Alpay
Date: February 8, 2003 at 17:18:36 Pacific
OS: 2000
CPU/Ram: 23
Comment:

Hi, i have a question!

I want to create multiple arrays depending on users input!

lets say i wanna create 5 arrays

x=0
while(x5)
{
char[] |__| = new char[10];
}

my question is how do i make up names? for it.. if i put i in there it doesnt recognize it!

Thanks in advance!



Sponsored Link
Ads by Google

Response Number 1
Name: Alpay
Date: February 8, 2003 at 17:20:59 Pacific
Reply:

Well it is screwed up a little


let me write again

while(x islessthan 5)
{

char[] ? = new char[];

}

I ment if i put 'x' there it doesnt work, gives me error..

thanks


0

Response Number 2
Name: gpp
Date: February 9, 2003 at 14:08:19 Pacific
Reply:

I'm not exaclty sure what your trying to do, but I think your getting the error because your trying to name the array with an integer...

thru each iteration your going to get:
char[] 0 = new char[];
char[] 1 = new char[];
char[] 2 = new char[];
and so on...

and I think you may need to declare the length or else set to null..
char[] x=null;
-or-
char[] x=new char[10];


0

Response Number 3
Name: Dubravko
Date: February 18, 2003 at 06:30:26 Pacific
Reply:

Try this:

First, you should declare an empty array. After that, user has to declare how many elements this array should have (let's say 5 elements, you can enter that value from keyboard). Then, you will have to create a new array with desired number of elements and, finally, make old array equal to the new array.
I believe that following code should work:

int numberOfElements;

char[][] initialField = null;

numberOfElements = 5;

if( numberOfElements > 0 )
{
char[][] newFieldSizedByUser = new char[numberOfElements][10];

initialField = newFieldSizedByUser;
}

Is far as I know, you have to use both arrays (you can't do that with only one array).


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Block TCP ports with VB Recommended Site or Book ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Java - creating multiple arrays.

Creating javascript arrays in forms www.computing.net/answers/programming/creating-javascript-arrays-in-forms/12156.html

Need help in creating multiple files using ba www.computing.net/answers/programming/need-help-in-creating-multiple-files-using-ba/19001.html

Array of objects in Java www.computing.net/answers/programming/array-of-objects-in-java/12255.html