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
Hello people, I was wandering if I could get some people to complete this questionnaire for my business course. It would be very
madam [21]
What do I have to do
3 0
2 years ago
Write a program that uses two input statements to get two words as input. Then, print the words on one line separated by a space
Shkiper50 [21]

word1 = input("Enter a word: ")

word2 = input("Enter a word: ")

print(word1 + " " + word2)

I hope this helps!

6 0
2 years ago
What are the similarities and differences between the binary and decimal systems?
maks197457 [2]

Answer:

A binary system is a system that functions on zeros and ones (0's and 1's).

A decimal system is an Arabic numeric system that has 10 as its base and uses a dot which is also called a decimal point to show fractions.

Differences

  • A decimal uses ten different digits which is 0-9 while a binary system uses just two digits 0 and 1
  • Decimal system was historically a Hindu-Arabic system while the binary system is just an Arabic system

Similarities

  • They are capable of performing arithmetic operations
  • They both can be represented in decimal form

5 0
2 years ago
¿Por qué es importante que lo países crezcan a nivel tecnológico?
IrinaK [193]

Answer:

Importancia de la tecnología en el crecimiento económico de los países. ... El desarrollo de estas vías tecnológicas aporta un aspecto positivo como el ahorro del tiempo, la disminución de los esfuerzos de los trabajadores que permite una economía progresiva.

Explanation:

4 0
2 years ago
Which term describes the distinct number of colors a graphic contains? (1 point)?
laila [671]
Your answer would be "Hue".
4 0
3 years ago
Other questions:
  • The sequence of folders to a file or folder is known as its _______.
    6·1 answer
  • What view and zoom setting do you need for true WYSIWYG display? Why?
    14·1 answer
  • What is the difference between an electronic notebook and electronic flash cards?
    8·1 answer
  • Knowing what you know about today’s video games, imagine what it would look like if you had to create a modern-day version of Sp
    6·1 answer
  • Of the sequences listed below, which shows the correct order of the steps in the incident management workflow: (1) authenticate
    14·1 answer
  • Write a couple of paragraph on 'limited government and its important'?​
    7·1 answer
  • PLEASE HELP QUICK WILL GIVE BRAINLY
    6·1 answer
  • A finally clause will execute:
    8·1 answer
  • Which are the 2 main elements that’s make up computer architecture?
    6·2 answers
  • Which storage device is not recommended as a permanent storage solution?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!