Categories
of program statements
The simple program below consists of a single class:TicketDiscount.java. Every Java class is composed of
program statements. Some statements, called compound statements are comprised of more than
one statement themselves.
class TicketDiscount
{
public static void main( String
args[] )
{
int age;
// assign a
random age (0 .. 99) to
// variable
'age'
age = (int) ( 100 *
Math.random() );
System.out.println("age is: " + age);
if( age >= 60 )
{
System.out.println( age + "is 60 or over" );
System.out.println("qualifies for discount");
}
}
}
There are several different categories of Java program
statement. They include input and output statements, statements to change the values of
variables, statements to send messages to objects, and statements to determine which
statement to execute next. The table below analyses some of the different categories of
statement that make up the implementation of the class TicketDiscount.java.Although in this module we have not
(yet) introduced each kind of statement, the table should help to illustrate how even a
simple Java program consisting of a single class may be made up of many different kinds of
statement.
Category of statement |
Example of statement from TicketDiscount.java
|
class
declaration |
class
TicketDiscount { ... } |
method declaration |
public static
void main( String args[] ) { ... } |
variable
declaration |
int age; |
comment |
// assign a
random age (0 .. 99) to //
variable 'age' |
variable
assignment |
age = (int) (
100 * Math.random() ); |
message sending
|
System.out.println("age
is: " + age); |
control |
if( age >=
60 ) {...} |
Back to top
RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights
reserved.
webmaster@globalcampus.com.eg
|