Would final String charData = 3.14159265; work?

A good answer might be:

No: charData is an object of type String and 3.14159265 (without the quotes around it) is a literal of primitive type double. The style of using bit patterns is completely different, and a simple assignment statement won't work.

How the Program Works

The characters "3.14159265" are contained inside String charData.

    final String charData = "3.14159265";
    double value;

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

The assignment statement works in its usual two steps:

  1. The expression on the right of the equal sign is evaluated.
    • The parseDouble() method from wrapper Class Double examines the characters and evaluates to a double value.
  2. That double value is assigned to the variable value.

Usually this is called converting from character data to double precision floating point. But in reality the character data remains unaltered; a floating point value is calculated from it, but it does not change.

QUESTION 3:

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

    final String charData = "6.67E-2";

Click Here after you have answered the question