Compare commits

...

4 Commits

Author SHA1 Message Date
xivihwa
6fc3cc244e Delete lab3 directory 2023-04-04 17:44:45 +03:00
xivihwa
3bbb7c8e54 Delete lab2 directory 2023-04-04 17:44:38 +03:00
xivihwa
1af299f8f7 Delete lab1 directory 2023-04-04 17:44:30 +03:00
xivihwa
4924bbe62f Merge pull request #2 from ASDjonok/ІО-25/01-Антоненко-Віолетта-Станіславівна
Done lab 1-3
2023-04-04 17:41:26 +03:00
24 changed files with 0 additions and 236 deletions

View File

@@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1 +0,0 @@
Main.java

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/FunctionCalculator.iml" filepath="$PROJECT_DIR$/FunctionCalculator.iml" />
</modules>
</component>
</project>

View File

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -1,51 +0,0 @@
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//C2 = 2501 % 2 = 1, і операція O1 буде відніманням (-).
//C3 = 2501 % 3 = 2
//C5 = 2501 % 5 = 1, і операція O2 буде діленням (/).
//C7 = 2501 % 7 = 4, тип індексів i та j буде char.
double result = 0; // результат
char i, j;
char operation1 = '-';
double constant = 2.0;
Scanner scanner = new Scanner(System.in);
System.out.print("Введіть значення n: ");
int n = scanner.nextInt();
System.out.print("Введіть значення m: ");
int m = scanner.nextInt();
// Обчислення значення функції S
for (i = 'a'; i <= 'a' + n - 1; i++) {
for (j = 'b'; j <= 'b' + m - 1; j++) {
try {
double value = (double) i / applyOperation(j, operation1, constant);
result += value;
} catch (ArithmeticException e) {
System.out.println("Ділення на нуль: " + e.getMessage());
} catch (Exception e) {
System.out.println("Виникла помилка: " + e.getMessage());
}
}
}
// Виведення результату
System.out.println("Результат: " + result);
}
// Метод, який застосовує операцію О1 до двох чисел
public static double applyOperation(char j, char operation, double constant) throws Exception {
switch (operation) {
case '-':
return (double) j - constant;
case '/':
if (constant == 0.0) {
throw new ArithmeticException("C не може бути рівним нулю");
} else {
return (double) j / constant;
}
default:
throw new Exception("Непідтримувана операція: " + operation);
}
}
}

Binary file not shown.

8
lab2/Matrix/.idea/.gitignore generated vendored
View File

@@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1 +0,0 @@
Main.java

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Matrix.iml" filepath="$PROJECT_DIR$/Matrix.iml" />
</modules>
</component>
</project>

View File

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -1,58 +0,0 @@
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
byte[][] matrix = {{4, 7, 3}, {4, 7, 6}, {7, 10, 9}};
//C5 = 2501 mod 5 = 1, тому C = B^T (транспонування матриці)
//C7 = 2501 mod 7 = 1, тому тип елементів матриці має бути byte
//C11 = 2501 mod 11 = 10, тому треба знайти середнє значення елементів матриці
// Виконуємо дію з матрицею: транспонування матриці B
byte[][] transposedMatrix = transposeMatrix(matrix);
System.out.println("Transposed matrix: ");
printMatrix(transposedMatrix);
// Виконуємо дію з матрицею C: знаходимо середнє значення елементів матриці
double average = calculateAverage(transposedMatrix);
System.out.println("Cереднє значення елементів матриці: " + average);
}
// Метод для транспонування матриці
private static byte[][] transposeMatrix(byte[][] matrix) {
int rows = matrix.length;
int columns = matrix[0].length;
byte[][] transposedMatrix = new byte[columns][rows];
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
transposedMatrix[j][i] = matrix[i][j];
}
}
return transposedMatrix;
}
// Метод для знаходження середнього значення елементів матриці
private static double calculateAverage(byte[][] matrix) {
int rows = matrix.length;
int columns = matrix[0].length;
int sum = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
sum += matrix[i][j];
}
}
return (double) sum / (rows * columns);
}
// Метод для виведення матриці на екран
private static void printMatrix(byte[][] matrix) {
for (byte[] row : matrix) {
System.out.println(Arrays.toString(row));
}
}
}

Binary file not shown.

View File

@@ -1,8 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1 +0,0 @@
Main.java

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/OperationsStrings.iml" filepath="$PROJECT_DIR$/OperationsStrings.iml" />
</modules>
</component>
</project>

View File

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -1,25 +0,0 @@
import java.util.HashSet;
public class Main {
public static void main(String[] args) {
String inputText = "Who are you? What is your name? Where are you from?";
int targetLength = 3;
try {
HashSet<String> uniqueWords = new HashSet<String>();
String[] sentences = inputText.split("[?]");
for (String sentence : sentences) {
String[] words = sentence.trim().split("\\s+");
for (String word : words) {
if (word.length() == targetLength) {
uniqueWords.add(word.toLowerCase());
}
}
}
System.out.println("Unique words of length " + targetLength + " in the input text are: " + uniqueWords);
} catch (Exception e) {
System.out.println("An error occurred: " + e.getMessage());
}
}
}

Binary file not shown.