Page 177 - Computer science 868 Class 12
P. 177

07


                                                                   STATEMENTS AND SCOPE

















                        Learning Objectives


                    7.1  Sequential Statements                        7.2  Conditional Statements
                    7.3  Iterative statements                         7.4   Jump Statements
                    7.4  Scope of the variables



                 In a program, any sort of action taken is specified by a Java program. Statements are a complete unit of execution.

                 Let us take an example.

                    int km = 1000;
                 The above statement means that the value 1000 is stored in an integer type of variable “km”.

                 Similarly,
                    double fahrenheit = 50;
                    double centigrade = (fahrenheit + 32)/9.0 * 5.0;
                 The above two statements indicate that 50 is stored in the variable fahrenheit which is used to calculate the centigrade.

                 Thus,
                 There are broadly three categories of Java statements. They are:

                 •  Declaration statement
                 •  Expression statement
                 •  Control flow statement
                 Let us understand each of them.

                 1.  Declaration statement: This statement is used to declare a variable. It consists of the data type and the name of the
                   variable. It may contain an assignment operator and a value.

                   For example:
                    int sum;
                    double calculate = 40.5;
                    String sentence = "India is my country";


                        Note:  Each statement must end with a semicolon (;).




                                                                                                                       175
                                                                                                 Statements and Scope  175
   172   173   174   175   176   177   178   179   180   181   182