Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write two methods that read data from the console and store the data in an array: a. The method: int readData(int [ ] x) reads

Write two methods that read data from the console and store the data in an array:

a. The method:     

                      int readData(int [ ] x)

reads a list of at most 100 integers into the array x. A sentinel 999 terminates the list. The method returns the size of the list.

Largest and Smallest

Design a method that determines the largest and smallest values stored in an integer array, x. Your method should return these values in an array of length two. Use the following algorithm:

Initialize variables currentBig and currentSmall to the larger and smaller values of x[0] and x[1]. Process the rest of the list, two elements at a time. Compare the larger of the two elements to currentBig , and replace currentBig if necessary.

Compare the smaller of the two elements to currentSmall, and replace currentSmall if necessary. Test your method in a program and include a method that reads a list, terminated by 999, into an array.

Step by Step Solution

3.34 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

Code file is also submitted at httpsgithubcomravir... 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

Discrete Mathematics and Its Applications

Authors: Kenneth H. Rosen

7th edition

0073383090, 978-0073383095

More Books

Students also viewed these Programming questions