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 11:00
The editing of digital photos us about the same level of difficulty as editing an analog photo
Answers: 2
question
Computers and Technology, 22.06.2019 17:30
Under which key category do the page up and page down keys fall? page up and page down keys fall under the keys category.
Answers: 1
question
Computers and Technology, 23.06.2019 04:20
4. a1. vince owns a television repair shop that is insured undera commercial package policy. the policy includes thebuilding and personal property coverage form and thecauses-of-loss broad form. the declarations page indicatesthat coverage applies to both the building and the namedinsured's business property. explain whether or not thefollowing losses would be covered under his policy.a. a fire occurs on the premises, and the building isbadly damaged.b. a burglar steals some money and securities from anunlocked safe.c. a business computer is damaged by vandals whobreak into the shop after business hours.d. a tornado touches down near the store. several tel-evision sets of customers in the shop for repair aredamaged in the storm.til
Answers: 2
question
Computers and Technology, 24.06.2019 13:20
In the insert table dialog box, you select the checkbox to create the first row as the header of the table.
Answers: 3
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
English, 19.03.2021 02:50
question
Business, 19.03.2021 02:50
question
History, 19.03.2021 02:50
question
English, 19.03.2021 02:50
question
Mathematics, 19.03.2021 02:50
question
Mathematics, 19.03.2021 02:50
Questions on the website: 13722361