![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Semin ew. 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.
![Use the following class to test the methods you develop
public class Test {
public static void main(String[] args) {
}
}
int[] [] m1
}
=
{
int[] [] m2 = {
{ 14, 11, 13, 12),
{
18, 15, 13, 13),
{ 19, 16, 15, 17 } };
{
54, 53, 51, 52 },
{ 51, 59, 52, 56},
{ 53, 54, 52, 58 } };
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).](https://content.bartleby.com/qna-images/question/489c0cf4-ea96-41de-b267-748df2bb9c58/033b2b08-d25c-47bb-9385-55e1841e0b75/wuiqwk_thumbnail.jpeg)
Transcribed Image Text:Use the following class to test the methods you develop
public class Test {
public static void main(String[] args) {
}
}
int[] [] m1
}
=
{
int[] [] m2 = {
{ 14, 11, 13, 12),
{
18, 15, 13, 13),
{ 19, 16, 15, 17 } };
{
54, 53, 51, 52 },
{ 51, 59, 52, 56},
{ 53, 54, 52, 58 } };
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):
all
a12 a13
a21
922
a23
a31 932
a33/
bil
+ b₂1
b31
b12 b13
₂2
23
b32
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
=
all + bil
a21 + b₂1
a31 + b31
The addition of the above two arrays is
68 64 64 64
69 74 65 69
72 70 67 75
a12 + b12
+ b22
a32 + b32
922
a13 + b13
23 + b23
a33 + b33)](https://content.bartleby.com/qna-images/question/489c0cf4-ea96-41de-b267-748df2bb9c58/033b2b08-d25c-47bb-9385-55e1841e0b75/knr0bos_thumbnail.jpeg)
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):
all
a12 a13
a21
922
a23
a31 932
a33/
bil
+ b₂1
b31
b12 b13
₂2
23
b32
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
=
all + bil
a21 + b₂1
a31 + b31
The addition of the above two arrays is
68 64 64 64
69 74 65 69
72 70 67 75
a12 + b12
+ b22
a32 + b32
922
a13 + b13
23 + b23
a33 + b33)
Expert Solution
![Check Mark](/static/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
![Blurred answer](/static/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Hello! I need some help with my Java homework. Please use Eclipse Please add comments to the to program so I can understand what the code is doing and learn Create a new Eclipse project named so as to include your name (eg smith15 or jones15). In this project, create a new package with the same name as the project. In this package, write a solution to the exercise noted below. Implement the following method that returns the maximum element in an array: public static <E extends Comparable<E>> E max(E[] list) Write a test program that generates 10 random integers, invokes this method to find the max, and then displays the random integers sorted smallest to largest and then prints the value returned from the method. Max sure the the last sorted and returned value as the same!arrow_forward1) Write a method that returns the range of an array of integers. The range is the difference between the highest and lowest values in the array. The signature of the method should be as follows. public static int computeRange(int[] values)arrow_forwardProblem Description - JAVA PROGRAMMING Use a Two-dimensional (3x3) array to solve the following problem: Write an application that inputs nine numbers, each of which is between 1 and 10, inclusive. Display the array after the user inputs each value. Rotate/flip the array by changing places. Make the rows columns and vice versa. You have to move the elements to their new locations. Remember to validate the input and display an error message if the user inputs invalid data. Documentation and the screenshot(s) of the results. Example: 1 2 3 4 5 6 7 8 9 the result will be : 1 4 7 2 5 8 3 6 9arrow_forward
- 1Code a JavaScript callback function for the Array.map method to ('Yu Yamaguchi') evaluate an array of integersidentify the integers that are Prime numbersreturn the Prime numbers in the new array 2 Code a JavaScript callback function for the Array.reduce method to evaluate an array of integersdetermine the smalles integerreturn the smalles integer Note: if there are identical integers, the function is to return the last one.arrow_forwardHow is this program written in java?arrow_forwardQuestion 1: Magic Matrix Magic square is an ? × ? matrix that is filled with the numbers 1,2,3, . . . . . , ?2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value. 6 1 8 7 5 3 2 9 4 Write a Java code to randomly generate a 3X3 matrix and check if the matrix is the magic square. In your code you must test two features: a. Does each of the numbers 1,2,3,….9 occur in the matrix? b. Are the sums of the rows, columns, and diagonals equal to each other? Note: to generate a random number use the method Math.random() which generates a pseudo random number greater than or equal to 0 and less than 1. Sample Output could be as follows: Sample 1: The randomly generated matrix is: 4 3 8 9 5 1 2 7 6 Sample 2: The randomly generated matrix is: 4 9 2 3 5 7 8 1 6arrow_forward
- strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Find all strobogrammatic numbers that are of length = n. For example, Given n = 2, return ["11","69","88","96"]. def gen_strobogrammatic(n): Given n, generate all strobogrammatic numbers of length n. :type n: int :rtype: List[str] return helper(n, n) def helper(n, length): if n == 0: return [™"] if n == 1: return ["1", "0", "8"] middles = helper(n-2, length) result = [] for middle in middles: if n != length: result.append("0" + middle + "0") result.append("8" + middle + "8") result.append("1" + middle + "1") result.append("9" + middle + "6") result.append("6" + middle + "9") return result def strobogrammatic_in_range(low, high): :type low: str :type high: str :rtype: int res = count = 0 low_len = len(low) high_len = len(high) for i in range(low_len, high_len + 1): res.extend(helper2(i, i)) for perm in res: if len(perm) == low_len and int(perm) int(high): continue count += 1 return…arrow_forward|(1st part) You are going to draw flowers a certain integral locations on a wall in your room. You have an array that stores the location of each flower as an integer. You want to better imagine how the wall will look with the drawn flowers. To do this you will create an array that will be as long as necessary to draw all the flowers. The array generated will be 1 if a flower is to be drawn at the location and 0 otherwise. Write a section of code that dynamically creates an array of the drawn flowers, based on the length of and the values of a given location array For example draw(6, {1,5,7}) should return {0,1,0,0,0,1,0,1 int draw (int length, int * location) }arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
![Text book image](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
![Text book image](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
![Text book image](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
![Text book image](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
![Text book image](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education