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
HELP!!! What would var d=?
sergiy2304 [10]

Answer:

51015

Explanation:

Var b is a string, and it'll treat addition like <em>string concatenation </em>(aka just adding a message.) Since it's concatenation, it'll then turn the numbers/integers into strings.

This kind of behavior might be different depending on the language, though. Some languages might not allow this. (For example, C and C++)

7 0
3 years ago
Por favor definir que es un pseudocódigo y que es un diagrama de flujo.
marusya05 [52]

Answer:

que

Explanation:

8 0
3 years ago
Read 2 more answers
What are your thoughts on the last nintendo direct
allsm [11]

Answer:

I don't know? How do you feel about them?

Explanation:

5 0
2 years ago
Read 2 more answers
Gloria is in her sophomore year of college and works part time. She has assignments saved on her home computer, her aunt's lapto
Tanzania [10]
I think this answer, "<span>Upload all existing documents to a cloud-based program," is correct. Hope I helped!!</span>
4 0
3 years ago
Read 2 more answers
When you hear music, read a printout, or view a video, you are using a computer's
Alik [6]

Answer:

Output device.

Explanation:

An output device can be defined as a hardware device that typically receives processed data from the central processing unit (CPU) and converts these data into information that can be used by the end user of a computer system.

All of the output device of a computer are known as peripheral devices and they provide data (informations) to the end users in various formats such as video, audio, texts, images etc.

Since output devices are peripheral devices, they can be connected to the computer system wirelessly or through a wired-connection (cable).

Some examples of output devices are monitor, speakers, printer, projector etc.

Hence, when you hear music, read a printout, or view a video, you are using a computer's output device.

5 0
3 years ago
Other questions:
  • Can you subnet the 172.16.128.0/17 network address to support this subnet?
    6·1 answer
  • Write a function decimalToBinaryRecursive that converts a decimal value to binary using recursion. This function takes a single
    11·1 answer
  • The INC and Dec instruction do not effect the__________ flag
    6·1 answer
  • You work for a large company. You need to implement a backup solution for your company that will allow you to perform multiple b
    11·1 answer
  • Suppose that you want to write a program that inputs customer data and displays a summary of the number of customers who owe mor
    14·1 answer
  • If you have two redo log groups with four members each, what’s the optimal number of disks you need to provide appropriate prote
    5·1 answer
  • Which domain indicates that a website is sponsored by a university or college?
    12·1 answer
  • Mary recently read about a new hacking group that is using advanced tools to break into the database servers of organizations ru
    14·1 answer
  • Describe two types of software suites supporting your answer with three examples each.
    12·1 answer
  • What is an advantage of using a fully integrated cloud based data analytics platform
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!