Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; /* * This program reads double values from a list (actually a string) using a scanner. It calculates the average of these values

import java.util.Scanner;
/*
* This program reads double values from a list (actually a string) using a scanner. It calculates the average of these values as
* well as the minimum value and the maximum value
* For example, if the values are: 20 10 30 40 then the average is (20+10+30+40)/4 = 25 and the min is 10 and the max is 40
*/
public class SequenceOfValues
{
public static void main(String[] args)
{
String numbers = "34 68 22 76.0 81 98 78 84 62";
 Scanner in = new Scanner(numbers);

boolean first = true;
double min = 0;
double max = 0;
double sum = 0.0;

// Use this variable to keep track of the number of floating point numbers read in from numbers
int numberOfValuesSeen = 0;
//-----------Start below here. To do: approximate lines of code = 14
// Use a while loop and read one number at a time using the scanner. Inside the loop, update variable sum and update variables min and max if necessary
// Don't forget to increment variable numberOfValuesSeen
// Use the boolean variable first (declared above) to determine if this is the first time through the loop.
// If so, set sum, min, max to the first value read from the scanner and set first to false
// Hint: never call in.nextDouble() more than once inside a loop - call it and assign the result to a variable. Use this variable to test the value

Step by Step Solution

3.38 Rating (157 Votes )

There are 3 Steps involved in it

Step: 1

import javautilScanner public class SequenceOfValues public st... 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_2

Step: 3

blur-text-image_3

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

Programming With Microsoft Visual Basic 2017

Authors: Diane Zak

8th Edition

1337102121, 9781337517058, 978-1337102124

More Books

Students also viewed these Programming questions