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, 23.06.2019 12:00
Which of these is a benefit of using objects in a powerpoint presentation? a. collaborators can create the external files while you create and edit the slide show. b. you can easily change the theme and design of the presentation. c. you can have older data in the source file while having up-to-date data in the presentation. d. collaborators can easily share the presentation.
Answers: 2
question
Computers and Technology, 23.06.2019 14:30
Open this link after reading about ana's situation. complete each sentence using the drop-downs. ana would need a minimum of ato work as a translator. according to job outlook information, the number of jobs for translators willin the future.
Answers: 3
question
Computers and Technology, 23.06.2019 19:00
Acompany is hiring professionals for web designing. the firm is small with few resources. they want employees who possess problem-solving skills and can independently carry out responsibilities. which kind of employee should they select?
Answers: 2
question
Computers and Technology, 24.06.2019 03:30
Auniform resource locator (url) is a formatted string of text that web browsers, email applications, and other software programs use to identify a particular resource on the internet. true false
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
Questions on the website: 13722367