go to previous page   go to home page   go to next page

Answer:

Yes, it prints:

Default Locale = en_GB
value = 123,456,789

The language is english and the country is Great Britain. Locales specify both language and country.

DecimalFormat Objects

The program uses a DecimalFormat object. Its format() method converts a number into an appropriately formatted StringBuffer. A StringBuffer is almost the same as a String except it can be modified. (Remember that String objects cannot be modified.) However, in this chapter, StringBuffers will never be modified.

The default locale determines the format used when a number is converted into a StringBuffer. The number may be a primitive (such as int or double) or a wrapper object (such as Integer or Double).

import java.util.Locale;
import java.text.*;

class IODemo
{
  public static void main ( String[] args )
  {
    int value = 123456789 ;
    
    System.out.println( "Default Locale = " + Locale.getDefault() );
    DecimalFormat decform = new DecimalFormat();   
    System.out.println( "value = " + decform.format(value) );
  }
}

The program uses the default behavior of DecimalFormat.format(). Later you will see methods that further affect the output of format().

QUESTION 3:

(Review :) What three characters might be used to separate the digits of an integer into groups of three, depending on where you are?