Variables and Data Types

AP Computer Science A· difficulty 4/5

double d = 0.1 + 0.2;
System.out.println(d == 0.3);

What is printed?

  • A

    0.3

  • B

    Error

  • C

    true

  • D

    false

    check_circle

Explanation

Floating-point arithmetic is not always exact; 0.1 + 0.2 produces a result slightly off from 0.3, so == returns false.

Want 10 more like this — adaptive to your weak spots?

Related questions