Hello guys, I'm new here, I was trying my homework for computer science which consists of making a basic Game of Life program with a 2D boolean array and a Random number with a seed, this is what I have so far:
when I run it and enter the 3 inputs it just gives me the IllegalStateException and I have no idea why, please helpimport java.util.*; public class Life { static Scanner console = new Scanner(System.in); /** * @param args */ public static void main(String[] args) { //String file = null; Scanner input; if(args.length > 0) { //file = args[0]; } else { System.out.println("Enter number of rows flowed by number of columns and a seed: "); //file = console.next(); } input = new Scanner(console.next()); boolean [][] matrix = readInput(input); System.out.println(matrix.length + " " + matrix[0].length); printMatrix(matrix); } /** * reads the input already entered by user * */ private static boolean[][] readInput(Scanner input) { int numRows; int numCols; Random ran = new Random(); String message1= "Please enter number of rows, columns, and a seed in that specific order"; try { numRows = input.nextInt(); numCols = input.nextInt(); ran.setSeed(input.nextLong()); if (numRows + numCols < 9) { System.out.println("Not enough space for an organism to survive, try again"); } boolean[][] matrix = new boolean[numRows][numCols]; createMatrix(matrix); for(int row = 1; row < matrix.length - 1; row ++ ) { for( int col = 1; col < matrix[row].length - 1; col++) { matrix[row][col] = ran.nextBoolean(); } } return matrix; } catch(NoSuchElementException e) { throw new IllegalStateException(message1); } } /** * Prints the matrix including the toxic border * */ private static void printMatrix(boolean[][] matrix) { for(int r = 0; r < matrix.length; r++) { for(int c = 0; c < matrix[r].length; c++) { System.out.println(matrix[r][c] + " "); } System.out.println(); } System.out.println(); } /** * Initializes a matrix by setting the array's entire content to false * @param matrix */ private static void createMatrix(boolean[][] matrix) { for(int r = 0; r < matrix.length; r++) { for(int c = 0; c < matrix[r].length; c++) { matrix[r][c] = false; } } } }