Java OCA OCP Practice Question 2161

Question

Which statement, when inserted at (1), will format and print either the value -123 or 123 in the terminal window?

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("|%-+5d|", 123);
  • (c) System.out.printf("|%(07d|", -123);
  • (d) System.out.printf("|%(-+7d|", -123);
  • (e) System.out.printf("|%-5d|", -123);
  • (f) System.out.printf("|%3d|", new Integer("-123"));
  • (g) System.out.printf("|%2$4d|", null, 123, true);
  • (h) All of the above


(h)

Note

The statements will produce the following output, respectively:

|(123)||+123 ||(00123)||(123)  ||-123 ||-123|| 123|



PreviousNext

Related