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
Q30: Which of the following is considered a
Q43: What does the following code snippet print?
Int
Q46: What is the output of the following
Q55: Insert a statement that will correctly terminate
Q56: What is the output of the following
Q57: What values does counter variable i assume
Q65: Choose the loop that is equivalent to
Q66: Which of the following loop(s) could possibly
Q95: Which statement about storyboards is true?
A)A storyboard
Q106: How many times does the following loop
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