Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[Java] The output's supposed to look like below: Enter a double or Q to quit: 9.5 Enter a double or Q to quit: 10.0 Enter

[Java] The output's supposed to look like below:

Enter a double or Q to quit: 9.5 Enter a double or Q to quit: 10.0 Enter a double or Q to quit: 8.7 Enter a double or Q to quit: 0 Enter a double or Q to quit: 5.2 Enter a double or Q to quit: -1 Enter a double or Q to quit: Q 10.0, 0.0, -1.0 -1.0 8.35 

but I'm getting below instead.

Enter a double or Q to quit: 9.5 Enter a double or Q to quit: 10.0 Enter a double or Q to quit: 8.7 Enter a double or Q to quit: 0 Enter a double or Q to quit: 5.2 Enter a double or Q to quit: -1 Enter a double or Q to quit: Q java.util.Scanner[delimiters=\p{javaWhitespace}+][position=21][match valid=false][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q\E][infinity string=\Q\E]-1.05.3999999999999995 

I think I massed up casting scanner somewhere, but not sure where.

I have no knowledge about try-catch, arrray, arraylist, palseDouble or anything else beside I used in my code, so do not provide them.

Thank you!

import java.util.Scanner; public class InputProcessing {

public static void main(String[] args) { System.out.print("Enter a double or Q to quit: "); Scanner input = new Scanner(System.in); double minimum = 0; double average = 0; double output = 0; int count = 0; boolean good = true; double userInput; do { count++; userInput = input.nextDouble();; output = output + userInput; if(minimum > userInput) { minimum = userInput; } if(output > 0) { average = output / count; } System.out.print("Enter a double or Q to quit: "); } while(input.hasNextDouble()); System.out.print(input); System.out.print(minimum); System.out.print(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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions