diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..07115cd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/IO_24/_02_Бондаренко_Тарас_Андрійович/lab1/Lab1.java b/src/IO_24/_02_Бондаренко_Тарас_Андрійович/lab1/Lab1.java new file mode 100644 index 0000000..79aebe1 --- /dev/null +++ b/src/IO_24/_02_Бондаренко_Тарас_Андрійович/lab1/Lab1.java @@ -0,0 +1,38 @@ +package IO_24._02_Бондаренко_Тарас_Андрійович.lab1; + +import java.util.Scanner; + +public class Lab1 { + public static void main(String[] args) { +// O1 = + +// C = 2 +// O2 = % +// i, j = short(-32.768 to 32.768) + final int c = 2; + double result = 0; + Scanner scan = new Scanner(System.in); + System.out.print("Enter a: "); + int a = scan.nextInt();// Entering a + System.out.print("Enter b: "); + int b = scan.nextInt();// Entering b + System.out.print("Enter n: "); + int n = scan.nextInt();// Entering n + System.out.print("Enter m: "); + int m = scan.nextInt();// Entering m + scan.close(); + + if (a >= n || b >= m || a <= -c && n >= -c || b <= 0 && m >= 0) { + System.out.println("Error! Division by zero"); + return; + } + + for (short i = (short) a; i <= n; i++) { + for (short j = (short) b; j <= m; j++) { + result += (double) (i % j) / (i + c); //Calculation of the result + } + } + System.out.println("\ns = " + result); // Outputting the result + + } +} + diff --git a/src/IO_24/_02_Бондаренко_Тарас_Андрійович/lab2/Lab2.java b/src/IO_24/_02_Бондаренко_Тарас_Андрійович/lab2/Lab2.java new file mode 100644 index 0000000..4043b62 --- /dev/null +++ b/src/IO_24/_02_Бондаренко_Тарас_Андрійович/lab2/Lab2.java @@ -0,0 +1,84 @@ +package IO_24._02_Бондаренко_Тарас_Андрійович.lab2; + +import java.util.Scanner; + +public class Lab2 { + public static void main(String[] args) { +// C5 = 2 +// C7 = 1 +// C11 = 4 + Scanner scan = new Scanner(System.in); + System.out.print("Enter the number of matrix rows: "); + int m = scan.nextInt(); + System.out.print("Enter the number of matrix columns: "); + int n = scan.nextInt(); + + System.out.println("\nFilling matrix A:"); + byte[][] matrixA = new byte[m][n]; // Creating MxN matrix A + scanMatrix(matrixA, scan); + + System.out.println("\nMatrix A"); // Printing matrix A + printMatrix(matrixA); + + System.out.println("\nFilling matrix B:"); + byte[][] matrixB = new byte[m][n];// Creating MxN matrix B + scanMatrix(matrixB, scan); + + scan.close(); + + System.out.println("\nMatrix B:");// Printing matrix B + printMatrix(matrixB); + + System.out.println("\nMatrix C:"); + byte[][] matrixC = new byte[m][n];// Creating matrix C + for (byte i = 0; i < m; i++) { + for (byte j = 0; j < n; j++) { + matrixC[i][j] = (byte) (matrixA[i][j] + matrixB[i][j]); + System.out.print(matrixC[i][j] + "\t "); + } + System.out.println(); + } + + byte evenSum = 0; // Sum for the largest numbers in even rows + byte oddSum = 0;// Sum for the smallest numbers in even rows + + for (byte i = 0; i < matrixC.length; i++) { + byte largest = Byte.MIN_VALUE; // variable for largest element + byte lowest = Byte.MAX_VALUE;// variable for smallest element + for (byte j = 0; j < matrixC[i].length; j++) { + if (i % 2 == 0) { + lowest = (byte) Math.min(lowest, matrixC[i][j]); + } else { + largest = (byte) Math.max(largest, matrixC[i][j]); + } + } + if (i % 2 == 0) { + oddSum += lowest; + } else { + evenSum += largest; + } + } + + System.out.println("\nSum of the biggest elements: " + evenSum); + System.out.println("Sum of the smallest elements: " + oddSum); + } + + private static void scanMatrix(byte[][] matrix, Scanner scan) { //Method for filling matrix + for (byte i = 0; i < matrix.length; i++) { + for (byte j = 0; j < matrix[i].length; j++) { + System.out.print("Enter element" + "[" + i + "]" + "[" + j + "]: "); + matrix[i][j] = scan.nextByte(); + } + } + } + + private static void printMatrix(byte[][] matrix) {//Method for printing matrix + for (byte[] row : matrix) { + for (byte el : row) { + System.out.print(el + "\t "); + } + System.out.println(); + } + } +} + diff --git a/src/IO_24/_02_Бондаренко_Тарас_Андрійович/lab3/Lab3.java b/src/IO_24/_02_Бондаренко_Тарас_Андрійович/lab3/Lab3.java new file mode 100644 index 0000000..0bdc553 --- /dev/null +++ b/src/IO_24/_02_Бондаренко_Тарас_Андрійович/lab3/Lab3.java @@ -0,0 +1,24 @@ +package IO_24._02_Бондаренко_Тарас_Андрійович.lab3; + +import java.util.*; + +public class Lab3 { + // String + // Надрукувати слова без повторень заданого тексту в алфавітному порядку за першою літерою. + + public static void main(String[] args) { + String text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Mauris a diam maecenas sed enim ut sem viverra. Amet est placerat in egestas erat imperdiet. Sed turpis tincidunt id aliquet risus. Amet porttitor eget dolor morbi non arcu risus quis. Elementum nibh tellus molestie nunc non blandit massa. Feugiat scelerisque varius morbi enim nunc faucibus. Ipsum faucibus vitae aliquet nec ullamcorper sit amet risus nullam. Quis enim lobortis scelerisque fermentum dui faucibus in. Sem viverra aliquet eget sit amet tellus cras adipiscing enim. Sed ullamcorper morbi tincidunt ornare. Sodales ut eu sem integer vitae justo eget magna. Mi ipsum faucibus vitae aliquet nec ullamcorper."; + String[] words = text.split("[\\p{Punct}\\s]+"); + List wordList = new ArrayList<>(Arrays.asList(words));//Class ArrayList implements interface List + // asList returns immutable list + Set wordSet = new HashSet<>(wordList);// Class HashSet implements interface Set + wordList.clear(); + wordList.addAll(wordSet); + wordList.sort(String::compareToIgnoreCase); + + for (String element : wordList) { + System.out.println(element); + } + } +} +