Java OCA OCP Practice Question 2545

Question

Consider the following program:

public class Main {
        public static void main(String []args) {
                System.out.printf("%3.4s %n", "hello world");
                System.out.printf("%05d", 123);
        }
}

Which one of the following options correctly provides the output of this program?

a)      lo//from  w ww .  j av a 2s  . co  m
     05123

b)      hell
      0123

c)      hello
     123

d)      hell
     00123

e)      hello world
     123


d)

Note

In first printf() method, %3.4s indicates that you want to print the first four characters of a string.

In the second printf() method call, %05d indicates that you wanted to print a minimum five digits of an integer.

If the number does not have enough digits, then the number will be preceded by leading zeroes.




PreviousNext

Related