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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 12:40, dkjfghdjk
In a response of approximately 50 words, explain why it would be essential for the successful a/v technician to participate in additional coursework, presentations and seminars offered by equipment manufacturers as well as annual conferences attended by colleagues in the industry.
Answers: 1
image
Computers and Technology, 23.06.2019 11:00, jolleyrancher78
What are the possible consequences of computer hacking? what is computer piracy? describe some examples. what are the effects of computer piracy? what are the possible consequences of computer piracy? what is intentional virus setting? describe some examples. what are the effects of intentional virus setting? what are the possible consequences of intentional virus setting? what is invasion of privacy? describe some examples. what are the effects of invasion of privacy? what are the possible consequences of invasion of privacy? what is an acceptable use policy and what is the purpose of the acceptable use policy what is intellectual property and how can you use it?
Answers: 1
image
Computers and Technology, 23.06.2019 22:30, cuki96
Lakendra finished working on her monthly report. in looking it over, she saw that it had large blocks of white space. what steps could lakendra take to reduce the amount of white space?
Answers: 3
image
Computers and Technology, 24.06.2019 00:10, roxymiller3942
Read each statement below. if the statement describes a peer-to-peer network, put a p next to it. if the statement describes a server-based network, put an s next to it. p - peer-to-peer s - server-based
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 in other subjects:

Konu
History, 16.04.2020 03:21