Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!