Wrapper Class Output

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

It is rounded to 2.0 (or 2,0 depending on your locale).

Wrapper Class Output

Recall (from the end of chapter 9C) that a wrapper class defines objects that each hold a primitive value. For example, objects of class Integer each hold one int (and some methods for manipulating ints). A wrapper object may be used as data for format(). Here is a program that shows this:

import java.text.*;

class IODemoWrapper
{
  public static void main ( String[] args )
  {
    Integer i = new Integer( 7654321 );
    Double  d = new Double ( 11000.0008 );
    
    DecimalFormat numform = new DecimalFormat(); 
    
    System.out.println( "integer = " + numform.format(i) + " double = " + numform.format(d) );
  }
}

The output of the program is (for a computer in the US):

integer = 7,654,321 double = 11,000.001

Again, the locale of your computer will affect the format. Also, notice that the output for the double is rounded.

QUESTION 7:

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