Answered step by step
Verified Expert Solution
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 removemodify 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 mainString args
Set up Scanner object for keyboard input.
Scanner keyboard new ScannerSystemin;
Input number of integers to store.
System.out.printNumber of integers: ;
int nrInts keyboard.nextInt;
Set up array to hold integers.
int nrs new intnrInts;
Enter integers into array.
forint ctr ; ctr nrInts; ctr
System.out.printInteger #ctr: ;
nrsctr keyboard.nextInt;
Print contents of array.
System.out.println
Contents of integer array:";
forint ctr ; ctr nrInts; ctr
System.out.printlnNrs ctr nrsctr;
Find largest integer in array.
int largest nrs;
forint ctr ; ctr nrInts; ctr
ifnrsctr largest
largest nrsctr;
System.out.println
Largest integer: largest;
Find smallest integer in array.
int smallest nrs;
forint ctr ; ctr nrInts; ctr
ifnrsctr smallest
smallest nrsctr;
System.out.println
Smallest integer: smallest;
Find average of integers in array.
int sum ;
forint ctr ; ctr nrInts; ctr
sum sum nrsctr;
sum nrsctr;
double average doublesumnrInts;
System.out.println
Average of integers: average;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started