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]
2 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]2 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
When saving a memo you created in Word, which one of the following extensions is automatically assigned to the document?
VMariaS [17]
What are the options and if it's meaning like when you save something it has .pdf .jpg or .doc after the title then it would be ".doc"
8 0
2 years ago
Which emails go to the draft folder
castortr0y [4]

Answer:

Hi there, the only emails that go to the draft folder are the emails that you start to write and then you don't finish it so you can go back and finish writing it later.

Explanation:

<h2>Hope this helps!! Please consider marking brainliest! Have a good one!!</h2>
6 0
3 years ago
Read 2 more answers
Bert started off his working life as a typesetter for a print house. With the advent of new technologies, Bert's job became redu
Inessa [10]

Answer:

Berth's job became redundant because she lacks the computing skills. Perhaps, she has been using manual or analog type writing machine to do her job and was doing it well but with the advent of computer that replaces analog type writer, she will become redundant.

Explanation:

She needs to learn how to use the computer to type and do her job efficiently in the print industry.

5 0
3 years ago
3-d metal printing, artificial intelligence, and self-driving cars are examples of ___________.
BabaBlast [244]
My name is Chris I'm sorry for being so late but no I got it and I will be there for being such a great time with you and your team and I will get back to you are you still looking I'm sorry for being a little bump it to the only thing I can think of is that a little bit of time
4 0
3 years ago
Read 2 more answers
To save your new document or presentation, click the Start Button
Vika [28.1K]
No you would click save or save as
3 0
2 years ago
Other questions:
  • What are some options available when using the Replace feature?
    13·1 answer
  • Janet manages the security of the database servers at the mortgage company where she works. The servers are Windows Server 2016;
    15·1 answer
  • Technological uncertainty:
    15·1 answer
  • Which heat transfer can be described as currents of warm air rising and cool air falling
    12·1 answer
  • Which of the following statements can be used as evidence that ancient Greek beliefs and art has been influential? Select the th
    9·2 answers
  • Friday Night Funkin Fans, does this count as a leak if I share it?
    13·2 answers
  • How does a project charter support the project manager in getting things for the project from other people?
    6·1 answer
  • How is information processed within a<br> motherboard between the hard drive, CPU and RAM,
    12·1 answer
  • So I tried asking for help with my code on stackoverflow but the people there were very condescending and mean plus my questions
    7·1 answer
  • If you want to remove the autocorrect options button from the screen, you can press the ____ key.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!