there is an issue in data.txt we have 4 rows and 3 cols and gives me error out of bound kindly someone solve this but when I pass 4x4 in rows and cols it works well but it didnt meet project requirement
public class ReadMagicSquare {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException {
// TODO code application logic here
Scanner sc = new Scanner(new BufferedReader(new FileReader("data.txt")));
int rows = 4;
int columns = 3;
int [][] myArray = new int[rows][columns];
while(sc.hasNextLine()) {
for (int i=0; i<myArray.length; i++) {
String[] line = sc.nextLine().trim().split(" ");
for (int j=0; j<line.length; j++) {
myArray[i][j] = Integer.parseInt(line[j]);
}
}
}
for(int i=0;i<myArray.length;i++){
for(int j=0;j<myArray.length;j++){
System.out.print(myArray[i][j]+" ");
}
System.out.println();
}
}
}
in data.txt file
2 -1 1
6 4 24
2 19 7