1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Elenna [48]
2 years ago
9

Create a list with 5 numbers and find the smallest and largest number in the list and also the sum and product of the numbers in

the list, Additionally, find the sum and product of the largest and the smallest number.
Computers and Technology
1 answer:
rusak2 [61]2 years ago
6 0

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);

   }

}

You might be interested in
What are the 3 biggest advancements in computers?
Georgia [21]

Answer:

abacus . Mesopotamia or China, possibly several thousand years BCE. ...

binary math . Pingala, India, 3rd century BCE. ...

punched card . Basile Bouchon, France, 1725. ...

Explanation:

:)

6 0
2 years ago
What is the simplest unit of a compound that maintains all the characteristics of the compound<br> ?
vlada-n [284]
A molecule is the simplest unit of a compound.
3 0
3 years ago
Your boss it trying to console into an old switch that he found in storage and wants to configure it. he asks you to describe wh
nika2105 [10]
I believe that the correct answer is c. look for a male connector with 9 pins.
5 0
3 years ago
Read 2 more answers
A search engine searches what to find a match for the query
mylen [45]

Answer:

your keyword

Explanation:

3 0
3 years ago
When you save a microsoft office file to onedrive, where are you saving it?
labwork [276]

Answer:

You're saving it to your personal OneDrive folder and uploading it to the OneDrive servers.

Explanation:

6 0
2 years ago
Other questions:
  • A(n) _____ is a fake online persona created to promote a particular point of view, often in praise of a firm, product, or indivi
    15·1 answer
  • Sam needs to create a spreadsheet for his coworkers. They will need to follow a crossed a long road of data. Sam would like to m
    15·1 answer
  • Create the SQL statements for displaying the results for each of the following scenarios in the Academic Database. Save these st
    13·1 answer
  • What else can Xbox do to help reduce negative online behavior? (250 minimum)
    6·1 answer
  • The common channel signaling (CCS) system provides a separate network dedicated to control and signaling over the PSTN. This ena
    15·1 answer
  • Create a program that prints out a list of all the divisors of a number stored in a variable. (If you don’t know what a divisor
    11·1 answer
  • Please help if you answer correcly i will give you brainelst!!!!!!!!!!!!!!!!!!
    6·2 answers
  • Can somebody PLEASE help me cancel my subscription I have tried so many different things and contacted support - they are no hel
    14·1 answer
  • What are the correct answers to the following questions?
    11·1 answer
  • Write a function solution that given an array a of n integers (between -100 and 100), returns the sign (-1,0,1) of product of al
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!