Last active
August 13, 2017 17:52
-
-
Save fazlerabbi37/3a79113d91024a42f3144b38afc17c53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Project matrix calculator sub method. | |
Auther: Fazle Rabbi | |
All Rights Recived @ 2015*/ | |
import java.util.Scanner; | |
public class FazleRabbi{ | |
public static void main(String args[]){ | |
Scanner sc= new Scanner(System.in); | |
System.out.println("Enter First Matrix Row"); | |
int r1=sc.nextInt(); | |
System.out.println("Enter First Matrix Column"); | |
int c1=sc.nextInt(); | |
System.out.println("Enter Second Matrix Row"); | |
int r2=sc.nextInt(); | |
System.out.println("Enter Second Matrix Column"); | |
int c2=sc.nextInt(); | |
int m1[][]= new int[r1][c1]; | |
int m2[][]= new int [r2][c2]; | |
for(int i=0;i<r1;i++){ | |
for(int j=0;j<c1;j++){ | |
System.out.println("Enter first array possition "+"["+i+"] "+"["+j+"]"); | |
m1[i][j]=sc.nextInt(); | |
} | |
} | |
for(int i1=0;i1<r1;i1++){ | |
for(int j1=0;j1<c1;j1++){ | |
System.out.println("Enter second array possition "+"["+i1+"] "+"["+j1+"]"); | |
m2[i1][j1]=sc.nextInt(); | |
} | |
} | |
int output[][]= new int [r1][c2]; | |
output=Add(m1,m2); | |
for(int i4=0;i4<r1;i4++){ | |
for(int j4=0;j4<c1;j4++){ | |
System.out.print(output[i4][j4]+" "); | |
} | |
System.out.println(); | |
} | |
} | |
//the sub method code goes here. | |
public static int [][] Sub(int matrix1[][],int matrix2[][]){ | |
int a= matrix1.length; | |
int b=matrix2[0].length; | |
int [][] m3=new int [a][b]; | |
for(int i3=0;i3<a;i3++){ | |
for(int j3=0;j3<b;j3++){ | |
m3[i3][j3]=matrix1[i3][j3]-matrix2[i3][j3]; | |
} | |
} | |
return m3; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment