diff --git a/Assignment 2.pdf b/Assignment 2.pdf new file mode 100644 index 0000000..0cfe0f8 Binary files /dev/null and b/Assignment 2.pdf differ diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..1bad843 --- /dev/null +++ b/Main.java @@ -0,0 +1,48 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + char[][] matrix = readInputs(); + + for (char[] row : matrix) { + for (char c : row) { + System.out.print(c + " "); + } + System.out.println(); + } + } + + public static char[][] readInputs() { + char[][] matrix = new char[9][9]; // Initialize a 9x9 matrix + try { + File file = new File("./input.txt"); + Scanner scanner = new Scanner(file); + + int row = 0; + while (scanner.hasNextLine() && row < 9) { + String line = scanner.nextLine(); + if (line.length() != 9) { + throw new IllegalArgumentException("Each line in the file must have exactly 9 characters."); + } + for (int col = 0; col < 9; col++) { + matrix[row][col] = line.charAt(col); + } + row++; + } + + if (row != 9) { + throw new IllegalArgumentException("The file must contain exactly 9 lines."); + } + + scanner.close(); + } catch (FileNotFoundException e) { + System.out.println("File not found"); + } catch (IllegalArgumentException e) { + System.out.println(e.getMessage()); + } + + return matrix; + } +} diff --git a/input.txt b/input.txt new file mode 100644 index 0000000..5ff6b13 --- /dev/null +++ b/input.txt @@ -0,0 +1,9 @@ +- 8 - - - - - 9 - +- - 7 5 - 2 8 - - +6 - - 8 - 7 - - 5 +3 7 - - 8 - - 5 1 +2 - - - - - - - 8 +9 5 - - 4 - - 3 2 +8 - - 1 - 4 - - 9 +- - 1 9 - 3 6 - - +- 4 - - - - - 2 - diff --git a/main.java b/main.java deleted file mode 100644 index 14b1646..0000000 --- a/main.java +++ /dev/null @@ -1 +0,0 @@ -public \ No newline at end of file