Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you are being asked to write some methods that operate on an array of int values. You will code all the methods

In this assignment you are being asked to write some methods that operate on an array of int values. You will code all the methods and use your main method to test your methods.

Your class should be named Array

Your class will have the following methods

  1. public static int sum(int[] arr)
  2. public static int sum(int[] arr, int firstIndex, int lastIndex)
  3. public static double average(int[] arr)
  4. public static double average(int[] arr, int firstIndex, int lastIndex)
  5. public static int maxValue(int[] arr)
  6. public static int maxValue(int[] arr, int firstIndex, int lastIndex)
  7. public static int indexOfFirstMaxValue(int[] arr)

For example, given the following array:

myArray = {45, 22, 18, 89, 82, 79, 15, 69, 100, 55, 48, 72, 16, 98, 57, 75, 44, 32, 21, 14, 7, 16, 49, 58, 72}

Your methods will return the following values:

Sum of whole array = 1253 Sum of elements 12-18 = 343 Average of whole array = 50.12 Average of elements 12-18 = 49.0 Max of whole array = 100 Max of elements 12-18 = 98 Index of first Max of whole array = 8 Index of first Max of elements 12-18 = 13 Count of elements below average of whole array = 13 Count of elements below average of elements 12-18 = 4 Rotating once myArray = {72, 45, 22, 18, 89, 82, 79, 15, 69, 100, 55, 48, 72, 16, 98, 57, 75, 44, 32, 21, 14, 7, 16, 49, 58} Rotating 5 more times myArray = {14, 7, 16, 49, 58, 72, 45, 22, 18, 89, 82, 79, 15, 69, 100, 55, 48, 72, 16, 98, 57, 75, 44, 32, 21} Reversing the array myArray = {21, 32, 44, 75, 57, 98, 16, 72, 48, 55, 100, 69, 15, 79, 82, 89, 18, 22, 45, 72, 58, 49, 16, 7, 14}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

3. How frequently do the assessments occur?

Answered: 1 week ago

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago