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
Nastasia [14]
3 years ago
8

Write Java code that creates an array of n integers myArray, by taking n integers from the user with duplications, and do the fo

llowing:
1- Print the elements of myArray,
2- Calculate the sum and the mean of myArray elements,
3- Copy the values of myArray to an array list named myArrayList, the array list must contain the elements of myArray without duplication,
4- Calculate the sum and the mean of myArrayList elem
Computers and Technology
1 answer:
skad [1K]3 years ago
3 0

Answer:

this should be what you need

Explanation:

import java.util.*;

public class ABC{

 public static void main(String[] args) {

   int n;

   //create scanner object

   Scanner sc = new Scanner(System.in);

   //ask for size of array

   System.out.print("Enter the size of array (n): ");

   //read the input

   n = sc.nextInt();

   //create an array of n length

   int [] myArray = new int[n];

   //ask user for array elements

   System.out.printf("Enter %d integers: ", n);

   //read array elements

   for(int i =0 ;i <5; i++)

     myArray[i] = sc.nextInt();

   

   //print the elements if myArray

   System.out.print("1 - The values of myArray are: [");

   for(int i =0 ; i < n; i++){

     System.out.print(myArray[i]);

     if(i < n-1)

       System.out.print(", ");

   }

   System.out.print("]\n");

   //calculate mean and sum of myArray elements

   int sum = 0;

   double mean = 0;

   for(int i = 0; i < n; i++)

     sum += myArray[i];

   

   mean = (sum*1.0)/n;

   //print the sum and mean of myArray

   System.out.printf("2 - The sum is: %d. The mean is: %.1f\n", sum, mean);

     

   //create an arraylist

   ArrayList<Integer> myArrayList = new ArrayList<Integer>();

   //copy the value of myArray to an arraylist without duplicates

   for(int i = 0; i < n; i++){

     if(!myArrayList.contains(myArray[i]))

       myArrayList.add(myArray[i]);

   }

   sum = 0; mean = 0;

   //display the values of myArrayList

   System.out.print("3 - The values of myArrayList are: [");

   for(int i =0 ; i < myArrayList.size(); i++){

     System.out.print(myArrayList.get(i));

     if(i < myArrayList.size()-1)

       System.out.print(", ");

   }

   System.out.print("]\n");

   //calculate sum and mean of myArrayList elements

   for(int i = 0; i < myArrayList.size(); i++)

     sum += myArrayList.get(i);

   mean = (sum*1.0)/myArrayList.size();

   //print the sum and mean of myArrayList

   System.out.printf("4 - The sum is: %d. The mean is: %.2f\n", sum, mean);

 }

}

You might be interested in
If I want to make it look like slide number one is turning a page to slide number two, what effect needs to be applied?
frozen [14]

Answer:

If you are talking about the latest version of PowerPoint, it's called a transition. I don't remember which one specificaly (idk if I spelled that right), but there's an option to pre-veiw the tranitions before you apply them.

Explanation:

I hope this helps!

3 0
4 years ago
The television is the biggest technological advancement in communication since the telephone.
docker41 [41]

Answer: just guess its a 50 50 %

Explanation:

4 0
3 years ago
Read 2 more answers
Jerry is working at the desk of a client in the marketing department of his company. The client thinks that the problem is the v
Softa [21]

Answer:

E. Check the simple things first to make sure you do not miss anything

Explanation:

This first step is called troubleshooting. As a certified operator, you need to check the simple things first to make sure you don't overlook something in your diagnosis.

The client is fairly certain the problem is from the video card, so after checking the simple things first (troubleshooting) and see no problems, then you can check the video card of the computer.

The reason it is advisable to troubleshoot on the simple things is to make sure you don't overlook something and also that your mind isn't totally fixed on one particular thing which is the video card in this situation.

5 0
4 years ago
PC’s &amp; More has shifted to sales and service of laptops and PCs, where it has the potential to triple the number of its cust
photoshop1234 [79]

Answer:

Growth Strategy

Explanation:

A growth strategy is a plan of action that allows you to achieve a higher level of market share than you currently have. Such as the case in the question, PC's shifted so sales and service of Laptops and PCs because there is a greater market share for them there than where they currently operate from.

5 0
3 years ago
What are some of the causes for error 1921 when updating?
Vikentia [17]

Below is a list of the several causes of runtime error 1921.

1. Incomplete or corrupt download of TurboTax software.

2. Virus infection that has corrupted Turbo or windows system files.

3. Another program mistakenly deleted TurboTax-related files.

4. Corruption in windows registry.

Error 1921 can be caused by other factors. Therefore, it is recommended to run a troubleshooting procedure for each of the possible causes. In addition, you can close all running programs including TurboTax and restart your computer. This will probably fix the error.


7 0
3 years ago
Read 2 more answers
Other questions:
  • Explain the design and development proccess?
    15·1 answer
  • How does soil lose its value? A.When the top soil is stripped by wind or water B.When the bedrock is damaged by animals C.When w
    15·1 answer
  • The more critical a component or service, the higher the level of availability required. True False
    5·1 answer
  • Main characteristic of open source software<br> ?
    7·1 answer
  • You are using the grep command, but it is only searching through files in your immediate home directory. What option enables you
    7·1 answer
  • Which UML relationships should be used between a subclass and a superclass? For example, suppose there is an interface or abstra
    5·1 answer
  • What should you do before using a website to store student information ? A. Read and understand the website’s privacy contract
    11·2 answers
  • When light does not pass through or bounce off an object, it is said to be
    13·2 answers
  • Complete the AscendingAndDescending application so that it asks a user to enter three integers. Display them in ascending and de
    7·1 answer
  • This study highlights that people access social networking sites to be
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!