ptg7068951
WHAT YOU’LL LEARN IN
THIS HOUR:
.Creating variables
.Using the different types of
variables
.Storing values into
variables
.Using variables in mathe-
matical expressions
.Storing one variable’s value
into another variable
.Increasing and decreasing
a variable’s value
In Hour 2, “Writing Your First Program,” you used a variable, a special stor-
age place designed to hold information. The information stored in vari-
ables can be changed as a program runs. Your first program stored a string
of text in a variable. Strings are only one type of information that can be
stored in variables. They also can hold characters, integers, floating-point
numbers, and objects.
During this hour, you learn more about using variables in your Java
programs.
Statements and Expressions
Computer programs are a set of instructions that tell the computer what to
do. Each instruction is called a statement. The following example from a
Java program is a statement:
int highScore = 450000;
You can use brackets to group a set of statements together in a Java pro-
gram. These groupings are called blockstatements. Consider the following
portion of a program:
1: public static voidmain(String[] args) {
2: int a = 3;
3: int b = 4;
4: int c = 8 * 5;
5: }
Lines 2–4 of this example are a block statement. The opening bracket on
Line 1 denotes the beginning of the block, and the closing bracket on
Line 5 denotes the end of the block.
HOUR 5
Storing and Changing Information
in a Program