AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Casting Primitive Data Types

APCSA-MZE08G

The following code segment outputs 13/5 = 2.0

 double answer = 13/5;
 System.out.println("13/5 = " + answer);

The programmer intends that it should print 13/5 = 2.6.

Which of the following changes to the first line of code will NOT fix the problem?

A

Casting 13 to a double (i.e. (double)13))

B

Writing 13 in floating-point notation (i.e. 13.0)

C

Casting 5 to a double (i.e. (double)5))

D

Writing 5 in floating point notation (i.e. 5.0)

E

Writing : double answer = (double)(13/5);