Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Transactions On Large Scale Data And Knowledge Centered Systems Xxiv Special Issue On Database And Expert Systems Applications Lncs 9510

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Hendrik Decker ,Lenka Lhotska ,Sebastian Link

1st Edition

366249213X, 978-3662492130

More Books

Students also viewed these Databases questions

Question

2. Outline the business case for a diverse workforce.

Answered: 1 week ago