Two Dimensional Matrix Sum
This commit is contained in:
@@ -1,12 +0,0 @@
|
|||||||
// Program to print Natural numbers from 1 to 10.
|
|
||||||
|
|
||||||
package IndustrialTrainingProjects;
|
|
||||||
|
|
||||||
public class NaturalNoPrint {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
for(int i = 1; i <= 10; i++)
|
|
||||||
{
|
|
||||||
System.out.println(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -24,4 +24,4 @@ if the problem still persist then create a issue or use Google/Stack Overlflow f
|
|||||||
|1 | [PrivateConBasic.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/PrivateConBasic.java) | Program to implement private constructor using the basic method. |
|
|1 | [PrivateConBasic.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/PrivateConBasic.java) | Program to implement private constructor using the basic method. |
|
||||||
|2 | [PrivateConSingleton.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/PrivateConSingleton.java) | Program to implement private constructor using the Singleton method. |
|
|2 | [PrivateConSingleton.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/PrivateConSingleton.java) | Program to implement private constructor using the Singleton method. |
|
||||||
|3 | [EmployeeModelClass.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/EmployeeModelClass.java) | Program to create Model Class, Getters, Setters and display the data. |
|
|3 | [EmployeeModelClass.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/EmployeeModelClass.java) | Program to create Model Class, Getters, Setters and display the data. |
|
||||||
|4 | [NaturalNoPrint.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/NaturalNoPrint.java) | // Program to print Natural numbers from 1 to 10. |
|
|4 | [TwoDimensionalArraySum.java](https://github.com/psavarmattas/Java-Projects/blob/master/IndustrialTrainingProjects/TwoDimensionalArraySum.java) | // Program to sum 2 two dimensional arrays forming a matrix. |
|
||||||
59
IndustrialTrainingProjects/TwoDimensionalArraySum.java
Normal file
59
IndustrialTrainingProjects/TwoDimensionalArraySum.java
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
// Program to sum 2 two dimensional arrays forming a matrix.
|
||||||
|
|
||||||
|
package IndustrialTrainingProjects;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class TwoDimensionalArraySum {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int rows = 2, columns = 2;
|
||||||
|
int[][] arrayA = new int[rows][columns];
|
||||||
|
int[][] arrayB = new int[rows][columns];
|
||||||
|
int[][] arraySum = new int[rows][columns];
|
||||||
|
|
||||||
|
Scanner sc=new Scanner(System.in);
|
||||||
|
|
||||||
|
System.out.println("\nEnter the 1st array elements : ");
|
||||||
|
for(int i=0; i<rows;i++) {
|
||||||
|
for(int j=0; j<columns;j++) {
|
||||||
|
arrayA[i][j]=sc.nextInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.print("\nMatrix of Array A : \n");
|
||||||
|
for(int []x:arrayA) {
|
||||||
|
for(int y:x){
|
||||||
|
System.out.print(y+" ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("\nEnter the 2nd array elements : ");
|
||||||
|
for(int i=0; i<rows;i++) {
|
||||||
|
for(int j=0; j<columns;j++) {
|
||||||
|
arrayB[i][j]=sc.nextInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.print("\nMatrix of Array B : \n");
|
||||||
|
for(int []x:arrayB) {
|
||||||
|
for(int y:x){
|
||||||
|
System.out.print(y+" ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < rows; i++) {
|
||||||
|
for (int j = 0; j < columns; j++) {
|
||||||
|
arraySum[i][j] = arrayA[i][j] + arrayB[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("\nSum of the given matrices is : ");
|
||||||
|
for(int i = 0; i < rows; i++) {
|
||||||
|
for (int j = 0; j < columns; j++) {
|
||||||
|
System.out.print(arraySum[i][j] + " ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user