java - How to successfully add up 2d matrices? -


sorry guys, i'm beginner in java , wondering if help.

import java.util.scanner; import java.util. arrays;  public class matrices_lab {     public static int summat( int[][] matty )     {       //code  }     public static void main(string[] args)     {        int[][] mat = {{2,3,4},{55,66,77},{22,11}};         system.out.println( summat( mat ) );     } } 

the //code part have fill in. have far not working.

 int[] finished_array;        for(int i=0; i<matty.length;i++){            for(int j=0; j<matty.length;j++){              int[] temp+=  matty[j][i];               finished_array=temp; 

can me out? how fill in function make work?

get first matrix, , second matrix. think, how add matrices...you need same (row, column) point each of them. then, loop through each point in matrix , it.

rows , columns should given, use own values

note: works 2 matrices. make function , keep looping through making matrices want.

ex.

private void makematrix() {     while("condition")        //code below matrix } 

       //first matrix        (int = 0; < rows; i++) {            (int j = 0; j < columns; j++) {                a[i][j] = foo.nextint();            }        }        //second matrix        (int = 0; < rows; i++) {            (int j = 0; j < columns; j++) {                b[i][j] = foo.nextint();            }        }        int[][] c = new int[rows][columns];        (int = 0; < rows; i++) {            (int j = 0; j < columns; j++) {                c[i][j] = a[i][j] + b[i][j];            }        }        //sum of 2 matrixes        (int = 0; < rows; i++) {            (int j = 0; j < columns; j++) {                system.out.print(c[i][j] + " ");            }            system.out.println(); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -