Java OCA OCP Practice Question 2163

Question

Which statement, when inserted at (1), will result in the program throwing an exception when run?

public class Main {
  public static void main(String[] args) {
    // (1) INSERT STATEMENT HERE
  }
}

    

Select the one correct answer.

  • (a) System.out.printf("|%-d|", -123);
  • (b) System.out.printf("|%3.0d|", 123);
  • (c) System.out.printf("|%d|", "false");
  • (d) System.out.printf("|%3d|", 123.45);
  • (e) System.out.printf("|%-5d|", 'a');
  • (f) System.out.printf("|%d|", new Character('h'));
  • (g) System.out.printf("|%d|", new Boolean("911"));
  • (h) System.out.printf("|%d|", false);
  • (i) All of the above.


(i)

Note

(a) will throw a java.util.MissingFormatWidthException. The width is not specified.

(b) will throw a java.util.IllegalFormatPrecisionException. The precision cannot be 0.

The remaining statements will throw a java.util.IllegalFormatConversionException.

The conversion d cannot be used with the specified argument.




PreviousNext

Related