Java OCA OCP Practice Question 2169

Question

Given the following code:

public class Main {
  public static void main(String[] args) {
    for (int i = 5; i < 10; i++) {
      System.out.format("|");
      for (int j = 0; j < 3; j++) {
        System.out.format("%" + i + "." + j + "f|", 123.456);
      }/*w  w  w . j a  va2s  .  com*/
      System.out.format("%n");
    }
  }
}

Which of the following lines will occur in the output of the program?

Select the one correct answer.

  • (a) | 123|123.5|123.46|
  • (b) | 123| 123.5|123.46|
  • (c) | 123| 123.5| 123.46|
  • (d) | 123| 123.5| 123.46|
  • (e) | 123| 123.5| 123.46|
  • (f) All of the above.


(f)

Note

Rows in the output are printed according to the following formats:

%5.0f, %5.1f, %5.2f
%6.0f, %6.1f, %6.2f
%7.0f, %7.1f, %7.2f
%8.0f, %8.1f, %8.2f
%9.0f, %9.1f, %9.2f

These formats result in the output shown in (a) to (e), respectively.




PreviousNext

Related