java program Add Two Array ( Matrices )
import java.util.Scanner; public class AR2 {
public static void main(String[] args) {
Scanner na = new Scanner(System.in);
int arr [] [] = new int
[3][3];
int arr1[][]=new int[3][3];
int arr2[][]=new int[3][3];
System.out.println("enter 1st matrix" );
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
arr1[i][j]=na.nextInt();
}
}
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
System.out.print(arr1[i][j]+"\t");
}
System.out.println();
System.out.println();
}
System.out.println("enter 2nd matrix" );
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
arr2[i][j]=na.nextInt();
}
}
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
System.out.print(arr2[i][j]+"\t");
}
System.out.println();
System.out.println();
}
System.out.println("Add matrix" );
for (int i=0;i<3;i++){
for (int j=0;j<3;j++){
arr [i][j] = arr1[i][j] + arr2[i][j];
System.out.print(arr[i][j]+"\t");
}
System.out.println();
}
}
}
0 comments:
Post a Comment