Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5.4.3 : Print the sum and average of an array's elements. Modify the program to print the average as well as the sum. Hint: You

5.4.3 : Print the sum and average of an array's elements.

Modify the program to print the average as well as the sum. Hint: You don't actually have to change the loop, but rather change what you print.

import java.util.Scanner;

public class ArraySum { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); final int NUM_ELEMENTS = 8; // Number of elements int[] userVals = new int[NUM_ELEMENTS]; // User numbers int i = 0; // Loop index int sumVal = 0; // For computing sum

// Prompt user to populate array System.out.println("Enter " + NUM_ELEMENTS + " integer values..."); for (i = 0; i

// Determine sum sumVal = 0; for (i = 0; i

return; } }

image text in transcribed

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

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

Students also viewed these Databases questions

Question

9. Power and politics can be destructive forces in organizations.

Answered: 1 week ago