Question: How do you fix this code snippet to make it print out the sum? The user will continue entering floating point numbers. If the user

How do you fix this code snippet to make it print out the sum? The user will continue entering floating point numbers. If the user enters a string value the loop will terminate.
import java.util.Scanner;
public class Mystery {
public static void main(String[] args){
System.out.print("Enter a value: ");
double sum =0;
Scanner in = new Scanner(System.in);
do
{
double value = in.nextDouble();
sum = sum + value;
System.out.print("Enter a value to add, or a letter to quit: ");
}
while (/* what code goes here? */);
System.out.println("sum "+ sum);
return;
}
}
Group of answer choices
in.hasData()
in.hasNextDouble()
!in.hasEnded()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!