Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify this program so activities take place in methods: Filling array., Printing array, Finding smallest integer in array, finding average of integers in the array.

Modify this program so activities take place in methods: Filling array., Printing array, Finding smallest integer in array, finding average of integers in the array. In methods, use array, not nrs, to reference array. Do not remove/modify statements in original program; instead, comment them out using /*. Do not use .toArray(). Program must contain all the original statements.
import java.util.Scanner;
public class ProgramMethods
{
public static void main(String[] args)
{
// Set up Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Input number of integers to store.
System.out.print("Number of integers: ");
int nrInts = keyboard.nextInt();
// Set up array to hold integers.
int[] nrs = new int[nrInts];
// Enter integers into array.
for(int ctr =0; ctr < nrInts; ctr++)
{
System.out.print("Integer #"+(ctr+1)+": ");
nrs[ctr]= keyboard.nextInt();
}
// Print contents of array.
System.out.println("
Contents of integer array:");
for(int ctr =0; ctr < nrInts; ctr++)
{
System.out.println("Nrs["+ ctr +"]"+ nrs[ctr]);
}
// Find largest integer in array.
int largest = nrs[0];
for(int ctr =1; ctr < nrInts; ctr++)
{
if(nrs[ctr]> largest)
largest = nrs[ctr];
}
System.out.println("
Largest integer: "+ largest);
// Find smallest integer in array.
int smallest = nrs[0];
for(int ctr =1; ctr < nrInts; ctr++)
{
if(nrs[ctr]< smallest)
smallest = nrs[ctr];
}
System.out.println("
Smallest integer: "+ smallest);
// Find average of integers in array.
int sum =0;
for(int ctr =0; ctr < nrInts; ctr++)
{
sum = sum + nrs[ctr];
// sum += nrs[ctr];
}
double average =(double)sum/nrInts;
System.out.println("
Average of integers: "+ average);
}
}

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

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions

Question

Explain the market segmentation.

Answered: 1 week ago

Question

Mention the bases on which consumer market can be segmented.

Answered: 1 week ago

Question

Explain consumer behaviour.

Answered: 1 week ago