Answer:
Explanation:
The following code is written in Java. It creates 5 random integers and saves them to a list called myList. Then it loops through that list and checks each one until the largest and smallest values are obtained. Finally, it uses these values to calculate the sums and products as requested. The program has been tested and the output can be seen in the attached image below.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
class Brainly {
public static void main(String[] args) {
Random rand = new Random();
ArrayList<Integer> myList = new ArrayList<>();
for (int i = 0; i< 5; i++) {
int mynum = rand.nextInt(20);
myList.add(mynum);
}
int largest = myList.get(0);
int smallest = myList.get(0);
int sum = 0;
int product = 1;
int sumLargestandSmallest, productLargestandSmallest;
for (int x : myList) {
if (x > largest) {
largest = x;
}
if (x < smallest) {
smallest = x;
}
sum += x;
product *= x;
}
sumLargestandSmallest = largest + smallest;
productLargestandSmallest = largest * smallest;
System.out.println("List" + Arrays.toString(myList.toArray()));
System.out.println("Smallest: " + smallest);
System.out.println("Largest: " + largest);
System.out.println("Sum: " + sum);
System.out.println("Product: " + product);
System.out.println("Sum of Smallest and Largest: " + sumLargestandSmallest);
System.out.println("Product of Smallest and Largest: " + productLargestandSmallest);
}
}