Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Finish the program below that uses a nested loop to compute the sum, product, and average of rows of numbers given in input. The program
Finish the program below that uses a nested loop to compute the sum, product, and average of rows of numbers given in input. The program will quit when the user inputs something that is not a number.
import java util. public class Lab5c public static void main (String args Scan the input Scanner scan [Your code here] Process each line separately If the next token is a double, assume there is an input line while (scan .hasNextDouble Get a line from the input String line [Your code here] Create a scanner for the line of input you have read Scanner linescan [Your code here] Write a while loop that will sum all of the double values on the line (hint: create double variables called "sum", product and "count". Set sum and count to 0, and product to 1 Then read as many double values as you can using the while loop When you read a number add it to sum, multiply product by it, and add 1 to count [Your code here] Compute the average by dividing sum by count [Your code here] Print out the sum, product, and average on one line [Your code here]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started