Question: /* * This program adds up all the integer numbers stored in an array and calculates the average. * The average is printed. * For

/*
*  This program adds up all the integer numbers stored in an array and calculates the average.
*  The average is printed.
*  For example, if the numbers are 1, 3, 5 then the average is (1+3+5)/3 = 4.5
*  Difficulty: Easy
*/
public class ArrayAverage
{
public static void main(String[] args)
{
int[] data = {2, 34, 57, 31, 5, 79, 88, 62, 98, 53, 42};

//-----------Start below here. To do: approximate lines of code = 4
// 1. set a variable total to zero; Hint: use a double!!


//2. use a for loop to add up all the integers in data. Recall we know the length of an array .length
// i.e. data.length




//3. compute the average

//-----------------End here. Reminder: no changes outside the todo regions.
System.out.printf("Average = %.2f", average) ;
  System.out.println("EXPECTED:") ;
  System.out.println("Average = 50.09") ;
}
}

Include screenshots too for formatting.

Step by Step Solution

3.49 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!