Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // multiplicacao de matriz
- import java.util.Scanner;
- public class Matriz {
- public static void main(String args[]) {
- Scanner leia = new Scanner(System.in);
- int mat1[][] = new int[3][3];
- int mat2[][] = new int[3][3];
- int mat3[][] = new int[3][3];
- for(int i=0; i<3; i++) {
- for(int j=0; j<3; j++) {
- mat1[i][j] = mat2[i][j] = 1;
- }
- }
- for(int i=0; i<3; i++) {
- for(int j=0; j<3; j++) {
- int aux = 0;
- mat3[i][j] = 0;
- /* Multiplica coluna por linha. Ex: c1l1 x c2l2 */
- for(int x=0; x<3; x++) {
- aux += mat1[i][x] * mat2[x][j];
- }
- mat3[i][j] = aux;
- }
- }
- System.out.println("\nMatriz 1");
- for(int i=0; i<3; i++) {
- for(int j=0; j<3; j++) {
- System.out.print(mat1[i][j] + "\t ");
- } System.out.print("\n");
- }
- System.out.println("\nMatriz 2");
- for(int i=0; i<3; i++) {
- for(int j=0; j<3; j++) {
- System.out.print(mat2[i][j] + "\t ");
- } System.out.print("\n");
- }
- System.out.println("\nMatriz 3");
- for(int i=0; i<3; i++) {
- for(int j=0; j<3; j++) {
- System.out.print(mat3[i][j] + "\t ");
- } System.out.print("\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement