Java Reference
In-Depth Information
FIGURE 2.4: Example program execution.
as the main project. For example, one can change the main project by right-clicking on the
project in the Projects view and selecting Set as Main Project .
2.2 Variables
Next, let us consider a more useful program. The user enters the temperature in degrees
Celsius and the program converts the temperature to degrees Fahrenheit. Before implement-
ing any program, we need to design an algorithm that solves the problem. An algorithm is
a sequence of steps that provides a recipe that addresses the problem at the logical level.
For our problem, an example algorithm can include the following steps.
1. Prompt the user to enter temperature in Celsius.
2. Read an integer form the keyboard and save it in memory location x .
3. Calculate the result of y =32+(9 / 5)
x , that is, the temperature in Fahrenheit, and
save y in memory.
4. Print the value of y on the screen.
Before transforming the algorithm into Java code, we need to learn about variables in
Java. Variables are a way of referring to cells in main memory. Java supports the primitive
types that are shown in Table 2.1. A variable name should always start with a lowercase
Search WWH ::

Custom Search