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
What is the correct method to reset the contents of the CMOS NVRAM on HP Desktop / Workstation computers after the AC power has
Ipatiy [6.2K]

It should be noted that in order to reset the content of the CMOS NVRAM on HP Desktop, one can turn off the power and turn it back on while the person is holding the shift key.

It should be noted that the non-volatile RAM simply means a complementary metal-oxide-semiconductor chip that can be found inside computers which is vital for storing information.

To reset the content of the CMOS NVRAM on HP Desktop, one can turn off the power and turn it back on while the person is holding the shift key.

Learn more about computers on:

brainly.com/question/24540334

5 0
3 years ago
When you are creating a game you plan to sell online and you need to implement art:
Lilit [14]

Answer:

you can download images that the creator has given permission to use freely.

Explanation:

5 0
3 years ago
Read 2 more answers
It's not possible to die in an alcohol-related collision if you're not in an automobile.
frutty [35]

Answer:

B. False

Explanation:

  • Consumption of alcohol is not a good practice and is generally not allowed at the time of driving an automobile and is considered to be an offense as it may be injurious to health and property.
  • As too much alcohol can create possible chances of collusions and even if the person is not in an automobile can result in a collision if tries to cross the road. Like head injuries or leg injuries can occur.
8 0
3 years ago
Why are computers assigned IP addresses?
ladessa [460]

Answer:An Internet Protocol address (IP address) is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. An IP address serves two main functions: host or network interface identification and location addressing.

6 0
3 years ago
What is the part of the browser window that displays the content of the web page such as pictures and text called?
iragen [17]
The frame is a part of the web page or browser window
5 0
3 years ago
Other questions:
  • Which is the most important reason you should properly cite information that you obtain from an Internet search? Question 2 opti
    8·1 answer
  • To activate a wizard to help in creating combo boxes and command buttons, make sure the ____ button is selected
    6·1 answer
  • A construction company has an online system that tracks all of the status and progress of their projects. The system is hosted i
    10·1 answer
  • If you want to insert a column into an existing table what would you do
    11·1 answer
  • Which website navigation method consists of a single web page containing a list of hyperlinks representing all the pages in the
    15·2 answers
  • When you type into a basic search engine like Google, Bing, or Yahoo!, the sites that appear at the top or on the side of the re
    7·1 answer
  • A typical setup for a ____ network would include computer users sharing a single internet connection.
    15·1 answer
  • Big data are used to _____. Select 3 options.
    5·1 answer
  • I still need help, thank you! Will give Brainliest ​
    10·1 answer
  • If your laptop is not able to connect to your wireless network, which of the
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!