Is the pattern in the int value 221 the same pattern as in the float value 221.0?

A good answer might be:

No. Integer and floating point types use bits in fundamentally different ways.

Converting a String to a Double

Here is a program that converts a String of characters into primitive type double. In this program, the characters that are converted are contained in a String literal. (We will do IO later on). The program will not run under versions of Java earlier than 1.2 because they do not have the parseDouble() method.

// This program requires Java 1.2 or higher
//
import java.io.*;
class StringToDouble
{
  public static void main (String[] args)
  {
    final String charData = "3.14159265";
    double value;

    value  = Double.parseDouble( charData  ) ;
    System.out.println("value: " + value +" twice value: " + 2*value );
  }
}

The reserved word final means that the value inside the variable charData will not change. This program is recommended for "copy-paste-and-run." Running the program writes the following to the screen:

C:\temp>java StringToDouble

value: 3.14159265 twice value: 6.2831853

The details of how this program works are on the next page.

QUESTION 2:

Would the program would work if the declaration of charData were changed to:

    final String charData = 3.14159265;

Click Here after you have answered the question