0
How can I read in a two dimensional array these file 10 10 10 255 0 0 23 45 92 48 74 83
12 Antworten
+ 3
Using FileReader class in nest for loop use split() method.
0
Can you be more specific please. Sorry if its bothers you.
0
Nested for loop
for(int i = 0; i < 4; ++i) {
for(int j = 0; j < 3; ++j) {
int x = arr[i][j];
}
}
Might have to do extra work to determine the size of the array, but that's the gist of it.
0
My for nest loop for the moment is
for( int i = 0; i<=50; i++)
{
for( int i2 = 0; i2 < 3; i2++)
ColorBalls[i][i2] = read.nextInt();
}}
// but it is throwing me an error, is that the proper way to read integer into a dimensional array?
0
My bad, jagged array element assignment in C# is:
ColorBalls[i, i2] = read.nextInt();
I presume nextInt() is returning a int?
0
Yes, but is not C# is java
0
Oh dang, my bad! Did you size the array appropriately?
int ColorBalls[][] = new int[50][3];
Also check to make sure there is a hasNextInt() before assignment. Maybe you're not reading what you expect to be?
0
When I try to read my file, it pops this error.
(Java.util.NoSuchElementException)
0
It means there is no nextInt(). If you used the look-ahead method hasNextInt I suggested this wouldn't occur.
Are you at least reading in some data? Do a step-by-step in debug. It may be that you're expecting N ints to be defined in the file but only N-1 exist.
0
So, how goes it? Any luck?
0
Yeah I couls fix it. Thank you for you help a lot.
0
Your welcome. Could you be so kind as to mark my response as the answer? It is the check mark next to my comment. Thank you.