Multiple choice general knowledge

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

  5. Prints 2.224578

  6. Prints .2224578

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

The format specifier '%.2f' rounds the double value to 2 decimal places. 222.4578 rounded to 2 decimal places is 222.46 (not 222.45, because the third decimal 7 causes rounding up). The printf method compiles and runs without error, printing the rounded value.