Menu
Topics Index
...
`

Print formatted strings


If you need explanation Read this topic

If you need Answer Take test on this topic

Print formatted strings
What will be the output of the following program?
public class StartProgram {

    public static void main(String arvs[]) {
        String args = "Hai this is %s example %s";
        System.out.print(String.format(args, "string", "= ", "This is "));
        String args1 = "and number is %d + %d";
        System.out.println(String.format(args1, 10, 15));
    }
}

A. Hai this is string example = and number is 25
B. Hai this is string example = and number is 10 + 15
C. Hai this is string example = This is and number is 10 + 15
D. Hai this is %s example %s and number is %d + %d
E. Hai this is string example = This is and number is 25
Topic: Java Formatter

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is B as args contains hi this is....  And args1 contains variable has 10 and 15 and prints and is not added as it takes as string

Posted by Bharath Yelchuri    2014-04-10 04:02:16


ans is b in args %s replaces with String and other %s replaces with = as there is no other format specifiers it doesn't print This is and arg1 replaces %d with given numbers

Posted by Navya Golla    2014-04-10 04:42:05


Answer is B it prints the output in the given order first it prints the string args and later prints string args 1 placing %d+%d as 10+15

Posted by Asad Ahmed    2014-04-10 04:58:39


Congratulations Navya Golla. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-04-11 04:29:04


© meritcampus 2019

All Rights Reserved.

Open In App