Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have to write this in an arraylist Write a Java code that asks the user to ent

ID: 3666272 • Letter: I

Question

I have to write this in an arraylist

Write a Java code that asks the user to enter an integer, n. Then it asks the user to enter n numbers. It stores all the numbers in an array list. It deletes the minimum number and then it finds the average of the remaining number. You can assume there is only one minimum in the list. (Make sure to use the enhanced for). PLEASE note that for this problem you don’t need to write a class.

e.g.

How many numbers you have: 4

Please enter your number(s): 3, 9, 16, 4

Program will print

Average is: 8

Max is: 16

Difference between each number and ave is: -5, 1, 8, -4

Explanation / Answer

ArrayList<Integer> list=new ArrayList<Integer>();

Scanner sc=new Scanner(System.in);

System.out.println("how many numbers you have");

int num=sc.nextInt();

int x;

for(int i=0;i<num;i++) // loop for reading n numbers into array list

{

x=sc.nextInt();

list.add(x);

}

int tot=0;

// calculation to find average

for(int k:list)

tot+=k;

ave=tot/num;

System.out.println("ave:"+ave);

//loop to calculate a max

int max=0;

for(int k:list)

{

if(k>max)

max=k;

}

System.out.println("Max:"+max);

//Difference between each number and ave is:

System.out.println("Difference between each number and ave is:");

for(int k:list)

System.out.println(k-ave +",");