Java Reference
In-Depth Information
Display 5.18
Use of the Method Double.parseDouble (part 2 of 2)
27 double number1 = Double.parseDouble(string1);
28 double number2 = Double.parseDouble(string2);
29 System.out.print("You input ");
30 System.out.println(number1 + " and " + number2);
31 }
32 }
Sample Dialogue
Enter two numbers on a line.
Place a comma between the numbers.
Extra blank space is OK.
41.98, 42
You input is 41.98 and 42.0
Self-Test Exercises
32. What is wrong with a program that starts as follows? The class ToyClass is
defi ned in Display 5.11 .
ToyClass anObject = null ;
anObject.set("Josephine", 42);
33. What is the type of the constant null ?
34. Suppose aVariable is a variable of a class type. Which of the following
correctly tests to see whether aVariable contains null ?
aVariable.equals( null )
aVariable == null
35. Is the following legal in Java? The class ToyClass is defi ned in Display 5.11 .
System.out.println( new ToyClass("Mr. Cellophane", 0));
TIP: Use Static Imports
You have already seen import statements, such as the following from Display 5.9:
import java.util.Scanner;
There is another form of import statement which, while not essential, can be a
convenience. These are called static import statements and are best explained with
an example.
static import
statement
(continued)
 
 
Search WWH ::




Custom Search