Answer:

That depends on where you are. Some possible choices are

123,456,789
123.456.789
123 456 789

In Canada, UK, and US, commas are used to separate groups of three digits. Other countries use periods or spaces for that purpose.

DecimalFormat Objects

The program creates a DecimalFormat object. The format() method of this object converts a number into a StringBuffer. A StringBuffer is almost the same as a String except it can be modified. No modification of a StringBuffer will be done in this chapter, so it will be treated exactly as if it were a String.

To utilize the DecimalFormat object, you need to import java.text.*; and set up a DecimalFormat constructor. Here is a complete program.

import java.text.*;

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

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

QUESTION 2:

Have the contents of the variable value been changed by format()?