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, 21.06.2019 13:30
The source manager dialog box allows you to create sources, copy sources created and used in all the documents, modify sources an add bibliographic information to placeholders. true or false
Answers: 2
question
Computers and Technology, 21.06.2019 20:50
Write a method in the heapintpriorityqueue class called merge that accepts another heapintpriorityqueue as a parameter and adds all elements from the other queue into the current queue, maintaining proper heap order such that the elements will still come out in ascending order when they are removed. your code should not modify the queue passed in as a parameter. (recall that objects of the same class can access each other's private fields.)
Answers: 2
question
Computers and Technology, 22.06.2019 08:30
Active listen eliminates barries to communication true or false
Answers: 1
question
Computers and Technology, 22.06.2019 09:00
Meenu wants to create a high quality drawing in a variety of colours. which device should she use for the same?
Answers: 1
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, 06.05.2021 20:00
question
Mathematics, 06.05.2021 20:00
question
Mathematics, 06.05.2021 20:00
question
Mathematics, 06.05.2021 20:10
question
Mathematics, 06.05.2021 20:10