Given: What is the result?
A.
The sum is 14
B.
Compilation fails
C.
The sum is 15
D.
The sum is 2
E.
The loop executes infinite times
Given: What is the result?
Given: What is the result?
A.
The sum is 14
B.
Compilation fails
C.
The sum is 15
D.
The sum is 2
E.
The loop executes infinite times
The question I’ve seen is…
public class Calculator {
public static void main(String[] args) {
int num = 5;
int sum;
do {
sum += sum;
} while ((num–) > 1);
System.out.println(“The sum is ” + sum + “.”);
}
}
and it fails to compile because sum has not been initialized.