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
Which model allows you to make subsystems in parallel?
boyakko [2]
The model is Parallel Distributed Processing Model (PDP) wherein m<span>Memory results from weblike connections among interacting processing units operating simultaneously, rather than sequentially ( also known as the connectionist model).</span>
8 0
3 years ago
Which domain refers to the equipment and data an organization uses to support its IT infrastructure. It includes hardware, opera
vovikov84 [41]

Answer:

D. System/Application Domain

Explanation:

A system or application domain is used by an organization to supports its IT infrastructure, holding all the business critical mission system, applications and data. All the resources of the company are contained in this domain, and is accessible by a member.

LAN to WAN domain links the company's infrastructure or local area network to a wide area network or the internet. The WAN domain simply holds publicly the data of an organisation, while remote access domain is meant for a small group of workers in the office or working from home.

8 0
3 years ago
Does anyone know how to write this right? This is for a coding class and I’m super confused on it.
vovangra [49]

Answer:

This is using c++ syntax, you might need to make slight adjustment for other languages.

First activity:

string firstSnack = "chips";

string secondSnack = "pizza";

string thirdSnack = "apples";

string bestSnack =  firstSnack;

bestSnack = secondSnack;

Second activity:

double apple = 0.5;

double banana = 0.75;

double orange = 1.43;

double total = apple + banana + orange;

Explanation:

When first declaring a variable, you want to specify the type (such as int, double, string, bool, etc.) and then the name. You can set the variable value in the declaration, or you can set it to a value later in the program by not having the equals sign and whatever comes next.

4 0
2 years ago
Concentric circles on a disk platter where data is stored;________
bagirrra123 [75]

Answer:

Tracks

Resilient File System (ReFS)

Explanation:

  1. Concentric circles on a disk platter where data is stored is called Tracks
  2. The new file system developed for Windows Server 2012 is called Resilient File System (ReFS). It allows increased stability for disk storage and improved features for data recovery and error checking
4 0
3 years ago
Most software packages have functions for generating _____ about columns of data, which include statistical summaries like contr
GrogVix [38]

Answer:

Descriptives is the correct answer of this question.

Explanation:

Some software packages provide data column definitions that include qualitative summaries such as control averages, mean, average, minimum, standard deviation, number of zero values, number of empty records, etc.

  • A  descriptives summary is a sentence that gives someone information or something.
  • Description is the style of narration creation aimed at making a location, an event, a character or a community vivid.

There are 2 types of Descriptives :-

  1. Narrative type.
  2. Argumentative type.

3 0
3 years ago
Other questions:
  • Jason is computer professional who has access to sensitive information. He shares this information with another organization in
    8·1 answer
  • What type of machine is a CD player? A. simple machine B. compound machine
    8·2 answers
  • How are engineers are related to technology
    13·1 answer
  • What element is not a selection in the Interface preferences? UI Character Presets UI Font Size UI Language UI Scaling
    9·1 answer
  • When adding cells you must use a "+" symbol, you cannot use a ":" symbol.<br><br> ☐ True<br> ☐ False
    13·1 answer
  • Please help it’s timed
    13·1 answer
  • Is anyone else having issues with brainly not working? Everytime I click on a answer it only comes up with the 7 month trail thi
    12·1 answer
  • ¿ El Parque Fray y Jorge es un patrimonio Cultural/Natural o patrimonial de Chile ?
    14·1 answer
  • What are foundations of any game systems that control what the players can or cannot do in the game, as well as the penalties, r
    8·1 answer
  • Try to crack the code:
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!