Analyze the following fragment:
double sum = 0;
double d = 0;
while (d != 10.0) {
d += 0.1;
sum += sum + d;
}
a. The program does not compile because sum and d are declared double, but assigned with integer value 0.
b. The program never stops because d is always 0.1 inside the loop.
c. The program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.
d. After the loop, sum is 0 + 0.1 + 0.2 + 0.3 + ... + 1.9
c The correct answer is C. There is no guarantee that d will be exactly 10.0 because real numbers are represented using approximation in a computer system.
You might also like to view...
Which statement is false?
a. Unless directed otherwise, the computer executes Java statements one after the other in the order in which they're written. b. Activity diagrams normally show the Java code that implements the activity. c. Like pseudocode, activity diagrams help programmers develop and represent algorithms. d. The arrows in
Which statement is false?
a. Based on whether an operator is implemented as a member function or as a non-member function, the operator is used differently in expressions. b. When an operator function is implemented as a member function, the leftmost (or only) operand must be an object (or a reference to an object) of the operator's class. c. Operator member functions of a specific class are called (implicitly by the compiler) only when the left operand of a binary operator is specifically an object of that class, or when the single operand of a unary operator is an object of that class. d. Another reason why you might choose a non-member function to overload an operator is to enable the operator to be commutative.
Find the “stopServer” shortcut icon on your desktop. When you click on it, a console window will open to run a stopServer.bat batch file in the
What will be an ideal response?
It is essential to be exact in row height and column width when drawing a table in PowerPoint
Indicate whether the statement is true or false