Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

(Java in Eclipse)

 Write code that finds the sum of two matrices. Use the following method header 
public static int[][] addMatrix(int[][] a, int[][] b)


The rules for adding two matrices are:
1. both matrices should have the exact same dimensions (i.e. height and width) – you need to check for this rule in your program.
2. both matrices should have elements that have compatible types – you don’t have to add extra code to check this rule in your method as it will only accept int arrays

included is a test class and a sample run

Use the following class to test the methods you develop
public class Test {
public static void main (String[] args) {
{ 14, 11, 13, 12 },
{ 18, 15, 13, 13 },
{ 19, 16, 15, 17 } };
int [] [] ml
%3D
{ 54, 53, 51, 52 },
{ 51, 59, 52, 56 },
{ 53, 54, 52, 58 } };
int [] [] m2
System.out.println ("First array:");
displayArray (ml);
System.out.println ("Second array:");
displayArray (m2);
/* write simple code to test your method and use
displayArray to display the result if applicable
//write your methods code here.
public static void displayArray (int [) m) {
for (int r = 0; r < m.length; r++) {
for (int c = 0; c < m[r].length; c++)
System.out.print (m[r] [c] + " ");
System.out.println ();
For all questions, assume that we use only rectangular arrays (i.e., all rows have the same length).
expand button
Transcribed Image Text:Use the following class to test the methods you develop public class Test { public static void main (String[] args) { { 14, 11, 13, 12 }, { 18, 15, 13, 13 }, { 19, 16, 15, 17 } }; int [] [] ml %3D { 54, 53, 51, 52 }, { 51, 59, 52, 56 }, { 53, 54, 52, 58 } }; int [] [] m2 System.out.println ("First array:"); displayArray (ml); System.out.println ("Second array:"); displayArray (m2); /* write simple code to test your method and use displayArray to display the result if applicable //write your methods code here. public static void displayArray (int [) m) { for (int r = 0; r < m.length; r++) { for (int c = 0; c < m[r].length; c++) System.out.print (m[r] [c] + " "); System.out.println (); For all questions, assume that we use only rectangular arrays (i.e., all rows have the same length).
As seen in the image below, the resulting matrix elements should be the sum of the respective pair
of elements from the two matrices (that are being added):
b1 b12 b13
aj1 + bi a12 + b12 a13 + b13
az1 + b21 a2 + b2 az3 + b3
a12
a13
b21 b2
b3
%3D
a23
a31
a32
a33/
b31
b32
b33)
a31 + b31
a32 + b32 a33 + b33
Test your program using the Test class
Sample run
First array:
14 11 13 12
18 15 13 13
19 16 15 17
Second array:
54 53 51 52
51 59 52 56
53 54 52 58
The addition of the above two arrays is
68 64 64 64
69 74 65 69
72 70 67 75
+
expand button
Transcribed Image Text:As seen in the image below, the resulting matrix elements should be the sum of the respective pair of elements from the two matrices (that are being added): b1 b12 b13 aj1 + bi a12 + b12 a13 + b13 az1 + b21 a2 + b2 az3 + b3 a12 a13 b21 b2 b3 %3D a23 a31 a32 a33/ b31 b32 b33) a31 + b31 a32 + b32 a33 + b33 Test your program using the Test class Sample run First array: 14 11 13 12 18 15 13 13 19 16 15 17 Second array: 54 53 51 52 51 59 52 56 53 54 52 58 The addition of the above two arrays is 68 64 64 64 69 74 65 69 72 70 67 75 +
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY