Solved

How Do You Fix This Code Snippet to Make It

Question 42

Multiple Choice

How do you fix this code snippet to make it print out the sum when the user enters Q? System.out.print("Enter a value, Q to quit: ") ;
Double sum = 0;
Scanner in = new Scanner(System.in) ;
Boolean hasData = true;
Do
{
Double value = in.nextDouble() ;
Sum = sum + value;
System.out.print("Enter a value, Q to quit: ") ;
}
While (in.hasNext() ) ;
System.out.println("sum " + sum) ;


A) while (in.hasData() ) ;
B) while (!in.hasEnded() ) ;
C) while (in.hasNextDouble() ) ;
D) while (hasData) ;

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions