import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

class Main {
	public static void main(String[] args) {

		int[] arr1 = new int[10];
		
		Scanner input = null;

		try {
			input = new Scanner(new File("info.txt"));
		}
		catch(FileNotFoundException e) {
			System.out.println("AHHHHHHH, can't open the file");
			return;
		}

		input.useDelimiter(",|\n");

		int idx = 0;
		while(input.hasNext()) {
			arr1[idx++] = input.nextInt();
		}

		printArray(arr1);

		int[][] arr2 = new int[3][3];

		try {
			input = new Scanner(new File("data.txt"));
		}
		catch(FileNotFoundException e) {
			System.out.println("AHHHHHHH, can't open the file");
			return;
		}

		input.useDelimiter(",|\n");

		for(int i = 0; i < arr2.length; i++) {
			for(int j = 0; j < arr2[i].length; j++) {
				arr2[i][j] = input.nextInt();
			}
		}
	
		printArray(arr2);

		int sum = 0;
		for(int i = 0; i < arr1.length; i++) {
			sum += arr1[i];
		}
		System.out.println("sum: " + sum);			
		
		sum = 0;
		for(int i = 0; i < arr2.length; i++) {
			for(int j = 0; j < arr2[i].length; j++) {
				sum += arr2[i][j];
			}
		}
		System.out.println("sum: " + sum);			
		
		int smallest = arr1[0];
		for(int elm : arr1) {
			smallest = (elm < smallest) ? elm : smallest;
		}
		System.out.println("smallest: " + smallest);

		smallest = arr2[0][0];
		for(int[] row : arr2) {
			for(int elm : row) {
				smallest = (elm < smallest) ? elm : smallest;
			}
		}
		System.out.println("smallest: " + smallest);

		arr1[arr1.length - 1] = 100;

		printArray(arr1);

		for(int i = 0; i < arr2.length; i++) {
			int[] row = arr2[i];
			for(int j = 0; j < row.length; j++) {
				arr2[i][row.length - 1] = 100;
			}
		}
	
		printArray(arr2);

		PrintWriter pw = null;

		try {
			pw = new PrintWriter(new File("info.bkup"));
		}
		catch(FileNotFoundException e) {
			System.out.println("File is not found");
			return;
		}

		for(int i = 0; i < arr1.length; i++) {
			pw.print(arr1[i]);
			if(i < arr1.length - 1) {
				pw.print(",");
			}
		}	
		pw.close();

		pw = null;
		try {
			pw = new PrintWriter(new File("data.bkup"));
		}
		catch(FileNotFoundException e) {
			System.out.println("File is not found");
			return;
		}

		for(int[] row : arr2) {
			for(int i = 0; i < row.length; i++) {
				pw.print(row[i]);
				if(i < row.length - 1) {
					pw.print(",");
				}
			}
			System.out.println();
		}	
		pw.close();
		
 
	}	

	public static void printArray(int[] arr) {
		for(int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
	}

	public static void printArray(int[][] arr) {
		for(int i = 0; i < arr.length; i++) {
			for(int j = 0; j < arr[i].length; j++) {
				System.out.print(arr[i][j] + " ");
			}
			System.out.println();
		}
	}
}
