Question
import java.util.ArrayList; import java.util.Scanner; /* * This program finds the largest and smallest numbers in an array list of integers */ public class FindMinAndMax {
import java.util.ArrayList;
import java.util.Scanner;
/*
* This program finds the largest and smallest numbers in an array list of integers
*/
public class FindMinAndMax
{
public static void main(String[] args)
{
String data = "45 72 35 90 12 3 204 317 684 23 44";
ArrayList values = new ArrayList();
Scanner in = new Scanner(data);
while (in.hasNextInt())
{
values.add(in.nextInt());
}
// Find the largest and smallest value in array list values
int largest = values.get(0);
int smallest = values.get(0);
//-----------Start below here. To do: approximate lines of code = 5
// Loop through the remaining integer elements in values and update largest and smallest
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
System.out.println("Largest = " + largest + " Smallest = " + smallest);
System.out.println("Expected:Largest = 684 Smallest = 3");
}
}
P.S: Please write the code as well as include screenshots for reference along with output
Step by Step Solution
3.40 Rating (147 Votes )
There are 3 Steps involved in it
Step: 1
import javautilArrayList import javautilScanner This program finds the largest and smalles...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