Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* * 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Discrete and Combinatorial Mathematics An Applied Introduction

Authors: Ralph P. Grimaldi

5th edition

201726343, 978-0201726343

More Books

Students also viewed these Programming questions

Question

What is the Antebellum Interregional growth hypothesis?

Answered: 1 week ago