Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2. Create a file named Hw1_part2.java, which has the following two methods. The first method receives an array of integers, which are sorted in

Part 2. Create a file named Hw1_part2.java,

which has the following two methods. The first method receives an array of integers, which are sorted in non-decreasing order, and calculates the mean, median, and the mode of these numbers and prints them on the screen.

We assume that the integers in the array are between 0 and 9, inclusively.

The median of a set of numbers is determined in the following way:

If the number of integers is odd, the middle number is the median.

If the number of integers is even, the average of two middle numbers is the median.

Example: The array has [2, 5, 5, 5, 7, 8, 8]. Median = 5 The array has [2, 2, 4, 4, 4, 7, 8, 8, 8, 8]. Median = (4 + 7) / 2 = 5.5 The mode of a set of numbers is a number that occurs most frequently.

The following shows examples:

The array has [2, 5, 5, 5, 7, 8, 8]. Mode = 5

The array has [2, 2, 4, 4, 4, 7, 8, 8, 8, 8].

Mode = 8 The signature of this method should be: public static void stats(int[ ] numbers) The second method is a main method.

If you run this program with the following main method: public static void main(String[] args) { int[] a = {2, 5, 5, 5, 7, 8, 8}; int[] b = {2, 2, 4, 4, 4, 7, 8, 8, 8, 8};

stats(a); stats(b); }

Your output should be: Mean = 5.714 Median = 5.0 Mode = 5 Mean = 5.5 Median = 5.5 Mode = 8

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

Postgresql 16 Administration Cookbook Solve Real World Database Administration Challenges With 180+ Practical Recipes And Best Practices

Authors: Gianni Ciolli ,Boriss Mejias ,Jimmy Angelakos ,Vibhor Kumar ,Simon Riggs

1st Edition

1835460585, 978-1835460580

More Books

Students also viewed these Databases questions

Question

Q .1. Different ways of testing the present adulterants ?

Answered: 1 week ago

Question

Q.1. Health issues caused by adulteration data ?

Answered: 1 week ago

Question

1. Traditional and modern methods of preserving food Articles ?

Answered: 1 week ago

Question

What is sociology and its nature ?

Answered: 1 week ago