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);
}
}