diff --git a/src/Lab1.java b/src/Lab1.java deleted file mode 100644 index 6e7403c..0000000 --- a/src/Lab1.java +++ /dev/null @@ -1,58 +0,0 @@ -public class Lab1 { - public static void main(String[] args) { -// char c = 'a' + '1'; - char c = 97; -// char c = '1'; - System.out.println(c); - System.out.println((int) c); - c++; - System.out.println(c); - System.out.println((int) c); - System.out.println((double)'1'/'3'); - -// System.out.println( (double) 0 / 0 ); -// System.out.println( Math.sqrt(-1) ); - double s = 0; - /*for (int i = 1; i <= 3; i++) { // 1) ��������� � i = 1, 2) ���� � <= 3, 3) �������� 䳿 � �� �����, - System.out.println(i); // 4) �������������� � �� 1, 5) ����������� �� ����� 2 -// s = s + i; - s += i; - }*/ - /*int[] array = new int[2]; - for (int i = 0; i < array.length; i++) { - - }*/ - final int A = -3; - final int B = 0; - final int N = 2; - final int M = 2; - - final int C = 1; -// boolean wasDivisionByZero = false; -// todo char -// todo[clear code] think about avoiding brackets - if ((A <= -C && -C <= N) || (B <= 0 && 0 <= M)) { - System.out.println("Division by zero!"); - return; - } -/*myLabel:*/for (int i = A; i <= N /*&& !wasDivisionByZero*/; i++) { - /*if (i + C == 0) { // todo optimize - System.out.println("Division by zero!"); - wasDivisionByZero = true; - break; //todo flag vs return; - }*/ - for (int j = B; j <= M; j++) { - /*if (j == 0) { - System.out.println("Division by zero!"); - return; -// wasDivisionByZero = true; -// break myLabel; - }*/ - s += (double) (i / j) / (i + C); - } - } -// if (!wasDivisionByZero) { - System.out.println("s = " + s); -// } - } -} diff --git a/src/Lab2.java b/src/Lab2.java deleted file mode 100644 index 473907c..0000000 --- a/src/Lab2.java +++ /dev/null @@ -1,26 +0,0 @@ -public class Lab2 { - public static void main(String[] args) { - int[] array = {1, 2, 3}; - /*for (int i = 0; i < array.length; i++) { - if (i % 2 == 0) { - System.out.println("!" + array[i]); - } else { - System.out.println("?" + array[i]); - } - }*/ - - for (int i = 0; i < array.length; i+=2) { - System.out.println("!" + array[i]); - } - - for (int i = 1; i < array.length; i+=2) { - System.out.println("?" + array[i]); - } - -// зубчасті матриці - int[][] matrix = { - {1, 2}, - {3} - }; - } -} diff --git a/src/lab2.java b/src/lab2.java new file mode 100644 index 0000000..4d02efd --- /dev/null +++ b/src/lab2.java @@ -0,0 +1,51 @@ +public class lab2 { + public static void main(String[] args){ + + // 2131 % 7 = 3; C7 = int + + int[][] matrix = { + {1,2,3,4,5}, + {1,3,5,7,9}, + {10,1,20,2,5} + }; + + int rows = matrix.length; + int column = matrix[0].length; + System.out.println("Матриця:"); + for(int i = 0; i < rows; i++){ + for (int j = 0; j < column; j++){ + System.out.print(matrix[i][j]+" "); + } + System.out.println(); + } + System.out.println(); + // 2131 % 5 = 1; C5 = транспортування; + + int[][] transportMatrix = new int[column][rows]; + + + for(int i = 0; i < rows; i++){ + for(int j = 0; j < column; j++){ + transportMatrix[j][i] = matrix[i][j]; + } + } + System.out.println("Транспонована матриця:"); + for (int i = 0; i < column; i++){ + for (int j = 0; j < rows; j++){ + System.out.print(transportMatrix[i][j]+" "); + } + System.out.println(); + } + System.out.println(); + + // 2131 % 11 = 8; C11 = Знайти середнє значення елементів кожного рядка матриці; + int sum; + for(int i = 0; i < rows; i++){ + sum = 0; + for(int j = 0; j < column; j++){ + sum += matrix[i][j]; + } + System.out.println("Середнє арифметичне " + (i+1) + " строки = " + (float)sum/column); + } + } +}