Menu
Topics Index
...
`

String Formats


If you need explanation Read this topic

If you need Answer Take test on this topic

String Formats
What will be the output of the following program?
public class StringFormat
{
    public static void main(String[] args)
    {
        double pi = Math.PI;
        System.out.format(Locale.CHINESE, "%f%n", pi);
        System.out.format("%-10.4f", pi);
        System.out.format("%-1.0f%n%n", pi * 100);
    }
}

A. 3.141593
3.1416    
314.1593
B. 3.141593
3.1416    314.1593
C. 3.141593
3.1416    314
D. 3.141593
3.1416    
314
E. Some other output
Topic: Other Advanced Topics In Java

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 C.

Posted by Gopinath Manchikanti    2014-08-26 13:30:19


c.Thejava.lang.String.format(String format, Object... args)method returns a formatted string using the specified format string and arguments..
frst print stmt wil prnt 3.141593
secnd wil-3.1416 n thrd 314..with no line chang

Posted by Asma Mujtaba Khan    2014-08-26 14:09:55


b
frst print stmt wil prnt 3.141593secnd wil->>3.1410 n thrd 314..with no line chang

Posted by Shamee Shamee    2014-08-26 14:12:07


e..there will b some other output othr dan dease sprcified

Posted by Wajahat Khan    2014-08-26 14:14:38


C

Posted by Raju VarshnEy    2014-08-26 14:26:36


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

Posted by Merit Campus    2014-08-27 04:40:25


© meritcampus 2019

All Rights Reserved.

Open In App