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]
3 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]3 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
Find the error in the following code fragment. int a: System.out.print(a):​
trapecia [35]

Answer:

If your using java, then its supposed to be "System.out.print("a")"    

Explanation:

its supposed to have quotations

7 0
3 years ago
Someone say crackhead
Ghella [55]

Answer:

................. crackhead

6 0
3 years ago
Read 2 more answers
_____ are different, even within the same job. a. Occupations b. Workplaces c. Careers d. Interest rates
pickupchik [31]
Hello,

Here is your answer:

The proper answer to this question is option B or "workplaces". Workplaces are where the person stays to do his or her job although they have the same job WORKPLACES are different.

Your answer is B.

If you need anymore help feel free to ask me!

Hope this helps!
3 0
4 years ago
Read 2 more answers
At one time, a station sign-off test pattern was designed so TV owners could adjust the quality of their picture and sound
mamaluj [8]

Answer:

true

Explanation:

7 0
3 years ago
To which type of domain does information on wikis belong?
Misha Larkins [42]

Answer:

Hope it helps you. ^_^

Explanation:

".info (TDLs)" domain.

3 0
3 years ago
Other questions:
  • A user would like to format an arrow that has been inserted into a chart. What is the most efficient method for completing this
    9·1 answer
  • Which is the value that expressions within conditional statements return?
    12·1 answer
  • If x window system is installed, linux users can use x11 forwarding to run __________ as they would on a windows computer. gui a
    11·1 answer
  • Kevin has to decide on a financial service provider that will help him with his needs related to tax exemptions and payments. He
    10·1 answer
  • Imagine a system with 64MB of physical memory. Suppose the OS and its data structures occupy 16MB and there are two processes, o
    12·1 answer
  • Join my among us code<br> SHUHZF
    6·2 answers
  • Convert the following denary numbers into
    14·1 answer
  • Simplify the expression 7(2y + 1) + 3y
    10·2 answers
  • Basic python coding, What is the output of this program? Assume the user enters 2, 5, and 10.
    8·1 answer
  • What type of html list will automatically place a list marker, or bullet point, indicator in front of each item? group of answer
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!