Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions