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
To type a small letter "z", you would use the right little finger. (5 points)True False
Klio2033 [76]
False you would choose the little finger...you would use the third finger.
4 0
4 years ago
1. Write a while loop that lets the user enter a number. The number should be multiplied by 10, and the result assigned to a var
shutvik [7]

Answer:

import java.util.Scanner;

public class num6 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       int product=0;

       do{

           System.out.println("Enter a number");

           int num = in.nextInt();

           product = num*10;

           System.out.println("The product is " + product);

       }while (product<100);

  }

}

Explanation:

In the Java program above, The user will be prompted to enter a number.

The number is multiplied by 10 and assigned to a variable called product.

A do....while loop has been implemented to check the variable product

As long as this variable is less than 10, the user will be prompted to enter another number.

3 0
3 years ago
Martha is a healer, a healthcare provider, and an experienced nurse. She wants to share her daily experiences, as well as her 12
STALIN [3.7K]
The answer to the question is blog.
4 0
4 years ago
Read 2 more answers
__________ implements a security policy that specifies who or what may have access to each specific system resource and the type
malfutka [58]

Answer: Access control

Explanation:

Access control implements a security policy that specifies who or what may have access to each specific system resource and the type of access that is permitted in each instance.

A typical example of this is in ERPs where access controls defines what access codes a process owner has and what access a reviewer and an approval has. Where a personnel has access to carry out a transaction, review and approve the transaction, access controls are said to be deficient.

The right answer is Access control

Hope this helps!!

6 0
3 years ago
Talia was a scientist whose research compared the birth rates of young women of a New England community over the course of five
podryga [215]

Answer: b

Explanation: for me personally i will populate an infographic(chart)rather than essay form i prefer to use an infographic to show my anaylis how it went high or low or when.

8 0
3 years ago
Read 2 more answers
Other questions:
  • _____ provide the standards, syntax, statements, and instructions for writing computer software
    14·1 answer
  • Infrared, a wireless connection used in the past prior to bluetooth, was limited because it ________.
    10·1 answer
  • The term median means
    9·2 answers
  • You are creating a database for your computer club. Most of the students live in your town, Durham. How can you make Durham appe
    11·1 answer
  • What term is given to pieces of computer software that allow you to manage your e-mail from your computer?
    12·1 answer
  • True or False (1 point each)
    9·1 answer
  • Why do you think it is important to consider ethical considerations when reviewing technology and assessing the impact of partic
    9·1 answer
  • You must regularly do this on your computer to prevent a virus from infecting it​
    9·2 answers
  • A folder is a collection of related of data is true or false​
    10·2 answers
  • Multiple Choice: Circle the letter that corresponds to the correct answer.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!