Suppose sum and num are int variables, and the input is
20 25 10 18 -1 What is the output of the following code? (Assume that console is a Scanner object initialized to the standard input device.) sum = 0;
Num = console.nextInt() ;
While (num != -1)
{
If (num >= 20)
Sum = sum + num;
Else
Sum = sum - num;
Num = console.nextInt() ;
}
System.out.println(sum) ;
A) 17
B) 28
C) 45
D) 60
Correct Answer:
Verified
Q26: After a break statement executes, the program
Q30: int i;for (i = 0; i <=
Q32: What is the output of the following
Q34: The do...while loop has an exit condition
Q36: ch = inFile.next().charAt();while (inFile.hasNext())
{
System.out.println(ch);
Ch = inFile.next().charAt();
}The above
Q37: What is the value of counter after
Q38: A break statement is legal in a
Q38: int i;for (i = 0; i <=
Q39: What is value of x after the
Q40: What is the output of the following
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