Question: Write a method named normalize() that accepts an argument which is reference to a two-dimensional (2D) NxN array with elements of type double. In

  1. Write a method named normalize() that accepts an argument which is reference  to a two-dimensional (2D) NxN array with elements of type double. In 


Write a method named normalize() that accepts an argument which is reference to a two-dimensional (2D) NxN array with elements of type double. In fact, the 2D array represents a square matrix (i.e., the number of rows is equal to the number of columns). The method should return a resulting 2D array of elements of type double, which is derived by the following instructions. a) The method first finds the difference between the average of its diagonals. Example1: {{1, 2, 3}, {4, 5, 6}, {1, 8, 9}} Average of first diagonal = (1+5+9)/ 3 = 5 Average of second diagonal = (3+5+1)/3 = 3 Difference = 5 - 3 = 2 Example2: {{1, 2, 3), (3, 4, 5), (5, 6, 7}} Average of first diagonal = (1+4+7)/ 3 = 4 Average of second diagonal = (3+4+5)/3 = 4 Difference = 4 -4 = 0 b) Use try-catch blocks to do the following. If the difference found in step (a) is not 0, then divide each element of array by the difference found in (a). . If the difference found in step (a) is 0, then throw an appropriate exception, and print "Runtime Exception" in the catch block and leave the array as is. c) Return the array derived in step (b). For Example1 in (a), the method returns the array: {{0.5, 1.0, 1.5), (2.0, 2.5, 3.0), (0.5, 4.0, 4.5}} For Example2 in (a), the method prints Runtime Exception and returns the array: {[1.0, 2.0, 3.0), (3.0, 4.0, 5.0), (5.0, 6.0, 7.0}} Submission instructions: Please submit only the java code for the method normalize() in the answer textbox by cut/paste or by directly coding in the textbox.

Step by Step Solution

3.43 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Logic to implement this method initialize sum of diagonals to 0 loop from i0 to i add value at row i ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!