Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////////KLASA MACIERZ////////////////////////////////////////////////////
- package com.cieslin;
- import java.util.Scanner;
- public class Macierz {
- Scanner s = new Scanner(System.in);
- private double[][] Tab;
- public double[][] createMatrix(int w, int k) {
- Tab = new double[w][k];
- for (int i = 0; i < w; i++)
- for (int j = 0; j < k; j++) {
- System.out.print("[" + (i + 1) + "][" + (j + 1) + "]:");
- Tab[i][j] = s.nextDouble();
- }
- return Tab;
- }
- public double[][] multiplyMatrix(double[][] TabA, double[][] TabB) {
- double suma = 0;
- double[][] Tab = new double[TabA.length][TabB[0].length];
- for (int i = 0; i < TabA.length; i++)
- for (int j = 0; j < TabB[0].length; j++) {
- suma = 0;
- for (int k = 0; k < TabA[0].length; k++)
- suma += TabA[i][k] * TabB[k][j];
- Tab[i][j] = suma;
- }
- return Tab;
- }
- public double[][] transpositeMatrix(double[][] Tab) {
- double[][] TabT = new double[Tab[0].length][Tab.length];
- for (int i = 0; i < Tab[0].length; i++)
- for (int j = 0; j < Tab.length; j++) {
- TabT[i][j] = Tab[j][i];
- }
- return TabT;
- }
- public void showMatrix(double[][] Tab) {
- for (int i = 0; i < Tab.length; i++) {
- for (int j = 0; j < Tab[0].length; j++)
- System.out.print(Tab[i][j] + "\t");
- System.out.println("");
- }
- }
- }
- ////////////////////////////////////////////////////////////////MAIN/////////////////////////////////////////////
- package com.cieslin;
- public class Main {
- public static void main(String[] args) {
- Macierz m = new Macierz();
- double[][] Tab = m.multiplyMatrix(m.createMatrix(3, 2), m.createMatrix(2, 2));
- m.showMatrix(Tab);
- m.showMatrix(m.transpositeMatrix(Tab));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement