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

Write a method named normalize() that accepts an argument which is reference to a two-dimensional (2D) NxN

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 (1.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 Examplel 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}}

Step by Step Solution

3.53 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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!