Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class MainProgram { public static SquareMatrix read(String location) throws IOException { File file = new File(location);
import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class MainProgram { public static SquareMatrix read(String location) throws IOException { File file = new File(location); Scanner input = new Scanner(file); int size = input.nextInt(); int[][] matrix = new int[size][size]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { matrix[i][j] = input.nextInt(); } } input.close(); return new SquareMatrix(matrix); } public static void write(String location, StringBuilder builder) throws IOException { File file = new File(location); PrintWriter writer = new PrintWriter(file); writer.println(builder); writer.close(); } public static void main(String[] args) throws IOException { String location = "data" + File.separator + "matrix.txt"; String otherLocation = "data" + File.separator + "other_matrix.txt"; String outputLocation = "data" + File.separator + "output.txt"; // Create object to append string output of matrix StringBuilder builder = new StringBuilder(" "); // TODO : Create matrices for testing // TODO : Test operations of Square Matrices // write to output file write(outputLocation, builder); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started