0

How can I read in a two dimensional array these file 10 10 10 255 0 0 23 45 92 48 74 83

26th Apr 2017, 2:26 AM
Isaac
Isaac - avatar
12 Respostas
+ 3
Using FileReader class in nest for loop use split() method.
26th Apr 2017, 3:23 AM
Nithiwat
Nithiwat - avatar
0
Can you be more specific please. Sorry if its bothers you.
26th Apr 2017, 3:09 AM
Isaac
Isaac - avatar
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.
26th Apr 2017, 3:10 AM
Mason Krei
Mason Krei - avatar
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?
26th Apr 2017, 3:43 AM
Isaac
Isaac - avatar
0
My bad, jagged array element assignment in C# is: ColorBalls[i, i2] = read.nextInt(); I presume nextInt() is returning a int?
26th Apr 2017, 4:48 AM
Mason Krei
Mason Krei - avatar
0
Yes, but is not C# is java
26th Apr 2017, 5:02 AM
Isaac
Isaac - avatar
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?
26th Apr 2017, 5:24 AM
Mason Krei
Mason Krei - avatar
0
When I try to read my file, it pops this error. (Java.util.NoSuchElementException)
26th Apr 2017, 8:17 PM
Isaac
Isaac - avatar
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.
26th Apr 2017, 8:28 PM
Mason Krei
Mason Krei - avatar
0
So, how goes it? Any luck?
28th Apr 2017, 5:27 PM
Mason Krei
Mason Krei - avatar
0
Yeah I couls fix it. Thank you for you help a lot.
28th Apr 2017, 5:29 PM
Isaac
Isaac - avatar
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.
28th Apr 2017, 5:31 PM
Mason Krei
Mason Krei - avatar