Menu
Topics Index
...
`

Strings and Locales


If you need explanation Read this topic

If you need Answer Take test on this topic

Strings and Locales
What will be the output of the following program?
import java.util.*;
public class FormatString
{
    public static void main(String[] args)
    {
        double valueOfPI = Math.PI;
        System.out.printf("%f\n", valueOfPI);
        System.out.printf(Locale.GERMAN, "%-10.3f", valueOfPI);
        
        double valueOfE = Math.E;
        System.out.printf("\n%f\n", valueOfE);
        System.out.printf(Locale.GERMAN, "%-10.3f", valueOfE);
    }
}

A. 3.141593
3.142     
2.718282
2.718
B. 3.141593
3,142     
2.718282
2,718
C. Compilation Error
D. Runtime Error
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 A..wen we are printg as float it wl print 6 decimals n later we restrctng to 3 after decimal

Posted by Uday Kumar    2014-07-07 03:55:12


Option B it prints value of PI and later Locale.GERMAN takes as currency in german belogs to java.util.Currency
prints 3,142 as result
It is similar to value of E also..

Posted by Sasikanth Sharma    2014-07-07 04:01:02


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

Posted by Merit Campus    2014-07-08 04:30:06


© meritcampus 2019

All Rights Reserved.

Open In App