SCJP Module-12 Question-10


 

SCJP Module-12 Question-10

The code given below will test your understanding that how to formate the number using the NumberFormate class in Java.

The code given below will test your understanding that how to formate the number using the NumberFormate class in Java.

Given below the sample code :

1  import java.text.*;
2  public class NumberformatClass {
3  public static void main(String args[]){
4  NumberFormat nf = NumberFormat.getInstance();
5  nf.setMaximumFractionDigits(4);
6  nf.setMinimumFractionDigits(2);
7  String a = nf.format(3.1415926);
8  String b = nf.format(2);
9  System.out.println(a);
10 System.out.println(b);
11 }}

The output of the above code is 3.1416, 2.00 ,What will be it's output ,if we remove line 5 & 6 ? 

1. Same output.

2. It will give Compile error.

3. 3.142    
    2.0

4. 3.142
    2

Answer

(4)

Explanation

The default value of Maximum fraction digit (after decimal) is 3 and minimum fraction digit is 0.

Ads