Revert "Delete lab2 directory"
This reverts commit 3bbb7c8e546087a93a7eb68a71424e8b666ccc73.
This commit is contained in:
		
							parent
							
								
									31ba116ad8
								
							
						
					
					
						commit
						4087daef02
					
				
							
								
								
									
										8
									
								
								lab2/Matrix/.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								lab2/Matrix/.idea/.gitignore
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
# Default ignored files
 | 
			
		||||
/shelf/
 | 
			
		||||
/workspace.xml
 | 
			
		||||
# Editor-based HTTP Client requests
 | 
			
		||||
/httpRequests/
 | 
			
		||||
# Datasource local storage ignored files
 | 
			
		||||
/dataSources/
 | 
			
		||||
/dataSources.local.xml
 | 
			
		||||
							
								
								
									
										1
									
								
								lab2/Matrix/.idea/.name
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								lab2/Matrix/.idea/.name
									
									
									
										generated
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
			
		||||
Main.java
 | 
			
		||||
							
								
								
									
										6
									
								
								lab2/Matrix/.idea/misc.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								lab2/Matrix/.idea/misc.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
<?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>
 | 
			
		||||
							
								
								
									
										8
									
								
								lab2/Matrix/.idea/modules.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								lab2/Matrix/.idea/modules.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
			
		||||
<?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>
 | 
			
		||||
							
								
								
									
										11
									
								
								lab2/Matrix/Matrix.iml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								lab2/Matrix/Matrix.iml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
<?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>
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								lab2/Matrix/out/production/Matrix/Main.class
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lab2/Matrix/out/production/Matrix/Main.class
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										58
									
								
								lab2/Matrix/src/Main.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								lab2/Matrix/src/Main.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,58 @@
 | 
			
		||||
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));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								lab2/lab2.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								lab2/lab2.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user