Hey guys I'm trying to input values into a 2 dimensional array in a program I am doing for school. My code is as follows:
import java.util.Arrays; import java.util.Scanner; public class Location { private int row; private int column; private int[][] array = new int[row][column]; public static void main(String[] args) { Scanner numberInput = new Scanner(System.in); System.out.println("Enter the number of rows and columns of the array: "); int row = numberInput.nextInt(); int column = numberInput.nextInt(); Location l1 = new Location(row, column); System.out.println("Please enter the array elements: "); for (int r = 0; r < l1.array.length; r++){ for (int c = 0; c < l1.array[r].length; c++) l1.array[r][c] = numberInput.nextInt(); } }//end main Location(){}//end constructor Location(int row, int column){ this.row = row; this.column = column; }//end arg constructor public double getMax(){ double max = -10000000; for (int i = 0; i < array.length; i++){ for (int j = 0; j < array[i].length; j++){ if (array[i][j] > max) max = array[i][j]; } } return max; } public Location locateLargest(double[][] x){ for (int i = 0; i < array.length; i++){ for (int j = 0; j < array.length; j++){ if (array[i][j] == getMax()) return x; } } }//end locateLargest() public int getRow(){ return this.row; }//end getRow() public int getColumn(){ return this.column; }//end getColumn() }//end class
When I try to input each individual value into the array using the for loop, It terminates right there. That means that its not getting my array lengths and I don't know why. Any help would be appreciated.