Limited access

Upgrade to access all content for this subject

Consider the following code segment.

double sum = 0;
for (int i=0; i<10; i++)
{
    sum = sum + 0.2;
    System.out.println(sum);
}

When the code is executed, the following unexpected output was generated:

0.2
0.4
0.6000000000000001
0.8
1.0
1.2
1.4
1.5999999999999999
1.7999999999999998
1.9999999999999998

Which of the following statements are TRUE concerning this situation?

I. Some floating-point numbers cannot be represented to one decimal place, because they contain non-numeric alphabetic characters.

II. Using an int data type for sum would have solved the printing problem.

III. Some floating-point numbers cannot be stored to the exact precision, since they are stored in binary format.

A

I only.

B

II only.

C

III only.

D

I and II only.

E

II and III only.

Select an assignment template