I am fairly new to java and I have a problem with following program:
import java.util.Scanner;
public class Matrix2D {
private double[][] matrix;
private int dimX;
private int dimY;
public Matrix2D(int row , int col ){
Scanner scanner=new Scanner(System.in);
dimX=col;
dimY=row;
matrix=new double[row][col];
int i ,j;
for( i=0;i<matrix[row].length;i++)
{
for( j=0;j<matrix[col].length;j++)
{
System.out.println("Please enter double at position"+" "+ row +" "+ col);
double input=scanner.nextDouble();
matrix[row][col]=input; }
}
}
public static void main(String[] args) {
Matrix2D test=new Matrix2D(3 ,3 );
}
}
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at Matrix2D.<init>(Matrix2D.java:17)
at Matrix2D.main(Matrix2D.java:31)
The program lets me give the first user input , but immediately after it throws the exception above. Any help would be much appreciated.