Solved

What Is the Output of This Code Snippet If the User

Question 10

Multiple Choice

What is the output of this code snippet if the user enters the numbers 1 2 3 4 -1 5?
Double total = 0;
Boolean hasValidNumber = true;
Scanner in = new Scanner(System.in) ;
While (in.hasNextDouble() && hasValidNumber)
{
Double input = in.nextDouble() ;
If (input < 0)
{
HasValidNumber = false;
}
Else
{
Total = total + input;
}
}
System.out.println(total) ;


A) 15.0
B) 14.0
C) 12.0
D) 10.0

Correct Answer:

verifed

Verified

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

Related Questions