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:
Verified
Q115: In the following code snippet, when does
Q116: Which for loop prints data across each
Q117: How many times will the output line
Q118: What will be the output of the
Q119: What is the last output line of
Q121: Suppose that the chance to hit the
Q122: What does the following code snippet display?
Q123: Which of the following is the correct
Q124: How many times does the following loop
Q125: Which of the following code snippets will
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents