![]() Topic awaiting preservation: Java - two dimensional arrays (Page 1 of 1) |
|
|---|---|
|
Bipolar (III) Inmate From: North Bay, Ontario, CA |
posted 10-07-2005 04:34
hmmm don't know if this actually fits in here... question about actual java - two dimensional array... wondering why this gives me an out of bound error: code: public class Matrix
{
private static int rows = 5;
private static int cols = 8;
public static void main(String[] args)
{
int[][] matrix = new int[rows][cols];
int r,c;
for (r=0; r < rows-1; r++)
for (c=0; c < rows-1; c++)
matrix[rows][cols] = 1;
}
} |
|
Lunatic (VI) Mad Scientist From: Massachusetts, USA |
posted 10-07-2005 04:41
You should be using matrix[r][c] instead of [rows][cols]. |
|
Bipolar (III) Inmate From: North Bay, Ontario, CA |
posted 10-07-2005 05:01
|
|
Bipolar (III) Inmate From: |
posted 10-07-2005 09:24
I guess it is a console application, so you can |
|
Paranoid (IV) Mad Scientist with Finglongers From: Germany |
posted 10-07-2005 09:26
and you should also do c < rows if you want to set all the rows. |