subject

Write the method in java sumofintegerdiv(int[] a, int n) which takes an array of integers a and an integer n as input and returns an integer. the return value is calculated by summing up the values that occur when you divide each element by the preceding element, until you stop at the n-th element in the array. your method should be resilient against possible exceptions, such as dividing by zero or attempting to access an invalid array index. instead of terminating when these exceptions occur, your method will instead skip the array index that generated the exception, print a friendly message to the user informing them why this index will be skipped, then resume computation normally (if possible).your method should be able to catch at least two types of exceptions:
-if an arithmeticexception occurred, your method should print the following message (before resum-ing computation normally): cannot divide by zero. skipping index: index_value
-if an occurred, your method should print the following message(before returning the result): cannot access array at index: index_value
-if any other type of exception occurred, then your method should print:
something went wrong! skipping index: index_value
notice that you should replace "index_value" above by the value of the actual array index.
examples: sumofintegerdiv({2, 4, 6, 0, 8, 16}, 4) returns 3 (4/2)+(6/4)+(0/6)4sumofintegerdiv({ 2, 4, 6, 0, 8, 16}, 5) returns 5 (4/2)+(6/4)+(0/6)+(16/8)
the second call skips (8/0) and prints a friendly error message to the user: "cannot divide by zero. skipping index: 4"

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:30
Ou listened to a song on your computer. did you use hardware or software?
Answers: 2
question
Computers and Technology, 23.06.2019 02:30
What is the power dissipated by a resistor with a current of 0.02 a and a resistance of 1,000 ? a. 200 w b. 20 w c. 0.4 w d. 4 w
Answers: 1
question
Computers and Technology, 23.06.2019 10:50
The volume v and paper surface area a of a conical paper cup are given by where r is the radius of the base of the cone and h is the height of the cone. a. by eliminating h, obtain the expression for a as a function of r and v. b. create a user-de ned function that accepts r as the only argument and computes a for a given value of v. declare v to be global within the function. c. for v ! 10 in.3 , use the function with the fminbnd function to compute the value of r that minimizes the area a. what is the corresponding value of the height h? investigate the sensitivity of the solution by plotting v versus r. how much can r vary about its optimal value before the area increases 10 percent above its minimum value?
Answers: 1
question
Computers and Technology, 24.06.2019 05:00
Who is most likely be your target audience if you create a slide presentation that had yellow background and purple text
Answers: 2
You know the right answer?
Write the method in java sumofintegerdiv(int[] a, int n) which takes an array of integers a and an i...
Questions
question
Mathematics, 14.04.2021 19:00
question
Mathematics, 14.04.2021 19:00
question
Mathematics, 14.04.2021 19:00
question
Mathematics, 14.04.2021 19:00
Questions on the website: 13722363