Here is code:
private static int[][] sumMatrices(int[][] A, int[][] B) {
int[][] C = new int[A.length][A[0].length];
for (int i = 0; i < A.length; i++) {
for (int j = 0; j < A[i].length; j++) {
C[i][j] = A[i][j] + B[i][j];
}
}
return C;
}
Sample code to test:
public class Sum {
public static void main(String[] args) {
int matA[][] = {{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}};
int matB[][] = {{12, 11, 10, 9},
{8, 7, 6, 5},
{4, 3, 2, 1}};
int[][] matC = sumMatrices(matA, matB);
for (int i = 0; i < matC.length; i++) {
for (int j = 0; j < matC[i].length; j++) {
System.out.print(matC[i][j] + " ");
}
System.out.println("");
}
}
private static int[][] sumMatrices(int[][] A, int[][] B) {
int[][] C = new int[A.length][A[0].length];
for (int i = 0; i < A.length; i++) {
for (int j = 0; j < A[i].length; j++) {
C[i][j] = A[i][j] + B[i][j];
}
}
return C;
}
}
Output:
Language Java Write a function named sumMatrices() that takes two matrices, say A and B, and...
Write a JAVA PROGRAM with function named getData() that takes a matrix A and an integer "row" as input parameters and returns an array containing all elements in the given row of A.
Write a java program that will read the values for 3 matrices A, B, and C and store the result of their summation in matrix D. You need to use a method to read matrix values. Use another method to add the three 3x3 matrices (each is a 2 dimensional array with 3 rows and 3 columns). Finally, use a third method to print the value of the summation (matrix D). Write a test program that will cal the three...
Write a Java program that will - read two 2x3 matrices A and B. - compute their sum (C=A+B) - print out the C matrix Please write out code. No screen shots please.
Using the programming language Java or C++, Write a function that takes an integer as input. Return true if this integer is a palindrome integer; false otherwise;
Language is Java! Write a class named Book that has two public String variables named title, and author. Do not add or change any other code.
4) Write a function named remove that returns void, takes in a string& called word, and an int called i that, starting from index 0, removes every ith letter from word by modifying it in place. Include a functional main method to make sure the program works. Programming language is C++, thanks in advance
Write a method to multiply two matrices. The header of the method is: public static double[][] multiplyMatrix(double[][] a, double[][] b) To multiply matrix a by matrix b, the number of columns in a must be the same as the number of rows in b, and the two matrices must have elements of the same or compatible types. Let c be the result of the multiplication. Assume the column size of matrix a is n. Each element is For example, for...
Intro to Java Programming Write a method named isDivisible that takes two integers, n and m, and that returns true if n is divisible by m, and false otherwise. Include your isDivisible() function as a method in Functions. In the main static method, demonstrate isDivisible() works by testing that it returns both possibilities correctly for a few different pairs of numbers. Include comments before your test code describing what's going on. The definition of divisibility is "One whole number is...
Write the definition code for a function named equation, that takes three numbers, n1, n2 and n3 and returns the value of (n1*n22)-3n2 +n3. Use the Python programming language
in python Write a function, named max_of_two, that takes two numbers as arguments and returns the largest of the two values. (Note, this function is actually already provided in Python as max. Do not use the provided function; reason through the logic yourself).