Multiple choice technology programming languages

class PrintTest{ public static void main(String[] args) { double d=222.4578; System.out.printf(“% .2f”,d); } }

  1. Does not compile

  2. Throws IllegalFormatConversionException

  3. Prints 222.46

  4. Prints 222.45

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The syntax System.out.printf("% .2f", d) uses a space flag, which prefixes positive numbers with a space, and .2 specifying two decimal places. The double value 222.4578 is formatted and rounded to two decimal places, outputting 222.46 (with a leading space), meaning it compiles and prints 222.46.