Java Reference
In-Depth Information
To Enter Code for the User Prompts, Inputs, and Conversions
1. With the insertion point on line 22 in the coding window, enter the
code from Figure 3-14 on page 147.
The System.out.println(), print(), readLine(), and parseInt() methods are
displayed (Figure 3-15). Line 31 is a blank line.
application
title
prompts
to display
to user
parseInt()
methods
readLine()
methods
FIGURE 3-15
In line 26, the readLine() method takes the value from the dataIn variable
location and assigns or copies it to the String location named height. The
parseInt() method then converts height to an integer and assigns it to a variable
location named inches. Java does not allow two variables with the same name
in the same procedure.
Operators
To complete a program task, a Java program may need to manipulate values
mathematically, such as adding or subtracting values, or it may need to evaluate
values logically, such as testing to see if the hours worked are greater than 40.
The Body Mass Index Calculator, for example, must divide the input value for
inches by 39.36 to convert it to meters. Performing mathematical or logical
operations in Java is similar to other programming languages and uses two basic
types of operators: arithmetic and comparison.
 
Search WWH ::




Custom Search