Question: Java: 1. Write a program that will do the following a. Ask the user to enter 7 integer numbers. b. store the numbers in an

Java:

1. Write a program that will do the following

a. Ask the user to enter 7 integer numbers.

b. store the numbers in an array.

c. define average method that computes the average of the values in the array.

d. Use Enhanced for loop to display the array on the console. Then display the average of the array.

This is what I have so far:

import java.util.Scanner;

public class Average {

public static void main(String[] args)

{

int n, sum = 0;

float average;

Scanner s = new Scanner(System.in);

//System.out.print("Enter no. of elements you want in array:");

//int a[] = new int[n];

int a[] = new int[6];

System.out.println("Enter the 7 digits:");

n = s.nextInt();

//for(int i = 0; i < n ; i++)

for(int i = 0; i < 7 ; i++)

{

a[i] = s.nextInt();

sum = sum + a[i];

}

//System.out.println("Sum:"+sum);

average = (float)sum / n;

System.out.println("Average:"+average);

}

}

Step by Step Solution

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 Databases Questions!