Question
[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
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