i need help with my code its intended to read from a file and take data and assign the first two numbers it reads as the size of the matrix, then i need it to display a matrix that assigns a number to a certain location in the matrix. IT MUST BE IN METHODS
i want it to read from a .dat file in the format of the following:
10 10
2 3 5
2 8 1
1 9 2
0 1 8
I want the out put to be:
0 0 0 0 0 0 0 0 0 0
0 8 0 0 0 0 0 0 0 2
0 0 0 5 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
import java.util.Scanner; import java.io.*; class lab16a { int[][] rix; public void size(int rows, int cols) { rix = new int[rows][cols]; return; } int rowsets,colsets,saves; public void store(int rowsets, int colsets, int saves) { rix[rowsets][colsets]=saves; return; } public void show() { for(int rowcount=0;rowcount<rix.length; rowcount++) { for(int part=0;part<rix[rowcount].length;part++) { System.out.print(rix[rowcount][part]+" "); } System.out.println(); } } public static void main (String[] args) throws FileNotFoundException { lab16a Run = new lab16a(); Scanner loc = new Scanner (System.in); System.out.println("Input File Location"); String File = loc.next(); loc = new Scanner (new File (File)); int row=loc.nextInt(); int col=loc.nextInt(); Run.size(row,col); while(loc.hasNext()) { int rowset=loc.nextInt(); int colset=loc.nextInt(); int save=loc.nextInt(); Run.store(rowset,colset,save); } Run.show(); } }