Skip to content

Instantly share code, notes, and snippets.

@purplecandy
Created February 11, 2020 11:30
Show Gist options
  • Save purplecandy/4fc6577608d03f4160190d5a0bdeefad to your computer and use it in GitHub Desktop.
Save purplecandy/4fc6577608d03f4160190d5a0bdeefad to your computer and use it in GitHub Desktop.
practical 6B
import java.io.*;
import java.util.Scanner;
class MatrixDemo {
final int r,c;
int i=0,j=0;
int ip1[][];
int ip2[][];
int op[][];
Scanner sc = new Scanner(System.in);
MatrixDemo(){
System.out.println("Enter the values of rows and column: ");
r=sc.nextInt();
c=sc.nextInt();
System.out.println("Value of ROW: "+r+" COL: "+c);
ip1 = new int[r][c];
ip2 = new int[r][c];
op = new int[r][c];
}
void input(int m[][]){
System.out.println("");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
System.out.println("Enter the value of "+(i+1)+"x"+(j+1));
m[i][j] = sc.nextInt();
}
}
}
void output(int m[][]){
System.out.println("");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
System.out.print(m[i][j] + "\t");
}
System.out.println("");
}
}
void add(){
System.out.println("");
System.out.println("Addition of Matrix");
for(i=0;i<r;i++){
for(j=0;j<c;j++){
op[i][j] = ip1[i][j] + ip2[i][j];
System.out.print(op[i][j] + "\t");
}
System.out.println("");
}
}
public static void main(String args[]){
MatrixDemo m = new MatrixDemo();
m.input(m.ip1);
m.output(m.ip1);
m.input(m.ip2);
m.output(m.ip2);
m.add();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment