Home Tutorial Java Scjp Part12 SCJP Module-12 Question-10

 
 

SCJP Module-12 Question-10
Posted on: July 22, 2010 at 12:00 AM
Advertisement
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.

Advertisement

Related Tags for SCJP Module-12 Question-10:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 22, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com