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 program. These groupings are called block statements. Consider the following portion of a program:

1: public static void main(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.

Some statements are called expressions because they involve a mathematical expression and produce a result. Line 4 in the preceding example is an expression because it sets the value of the c variable equal to 8 multiplied by 5. You work with expressions during this hour.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.20.231