Hello I am a beginner programmer and I have tried various different methods to get my code to work, but all of them have failed. I would be very thankful if someone could show me what it wrong with my code and how to fix the arrayindexoutofboundsexception error. Thank you so much in advance!!!
Here is my code:
public static void main(String[] args) {
// TODO code application logic here
// getting the number of rows and columns for the maze from the user
Scanner scanner = new Scanner(System.in);
System.out.print("How many rows are in the maze? ");
int rows = scanner.nextInt();
int[][] maze = new int[rows][];
System.out.print("How many columns are in the maze? ");
int columns = scanner.nextInt();
maze[rows] = new int[columns];
// getting the data/danger levels for each row from the user
for (int c = -1; c < maze[rows].length; c++) {
System.out.print("Enter the danger in row " + (c + 1) + ", " + "separated by spaces: ");
maze[rows][c] = scanner.nextInt();
}
System.out.println(maze[rows][columns] + "\n");
}
}