daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Christopher Miller AP CS Mod 4/5
  2. public class Matrix {
  3.    private int [][] mat;
  4.    
  5.    public Matrix( int numRows, int numCols ) {
  6.       mat = new int[ numRows ][ numCols ];
  7.    }
  8.    public void setValues( int[][] values ) {
  9.       for(int row = 0; row< mat.length; row++){
  10.          for(int col = 0; col<mat[row].length; col++){
  11.             mat[row][col] = values[row][col];
  12.          }
  13.       }
  14.    }
  15.    public Matrix add( Matrix mx ){
  16.       Matrix temp = new Matrix( mat.length, mat[0].length );
  17.       for(int row = 0; row< mat.length; row++){
  18.          for(int col = 0; col<mat[row].length; col++){
  19.             temp.mat[row][col] = mx.mat[row][col]+mat[row][col];
  20.          }
  21.       }
  22.       return temp;
  23.    }
  24.    public Matrix scalar( int n ){
  25.       Matrix temp = new Matrix( mat.length, mat[0].length );
  26.       for(int row = 0; row< mat.length; row++){
  27.          for(int col = 0; col<mat[row].length; col++){
  28.             temp.mat[row][col] = n*mat[row][col];
  29.          }
  30.       }
  31.       return temp;
  32.    }
  33.    public String toString() {
  34.       String n = "";
  35.       for(int row = 0; row< mat.length; row++){
  36.          for(int col = 0; col<mat[row].length; col++){
  37.             n += mat[row][col]+"\t" ;
  38.          }
  39.        n+="\n";
  40.       }
  41.       return n;
  42.      
  43. }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top