Page 101 - 2617_JSSPS_C-7
P. 101

When you enter the value 22, then the output will appear as shown:


















                 When you enter the value 7, then the output will appear as shown:

















                 Since the condition (7 % 2 == 0) returns false, the statement inside the body of the if statement does
                 not get executed and only the statement outside the if statement gets executed.

                 The if…else Statement

                 The if…else statement is used to execute either of the blocks of statements from if or else statements.
                 When the condition next to the if keyword evaluates to true, the statement(s) inside the if block will be
                 executed. Otherwise, the statement(s) inside the else block will be executed.


                                                     Start







                                                  Conditional     False     Body of else
                                                  Expression



                                                         True

                                                   Body of if





                                                      Stop


                                                    Flowchart of if ....else statement




                                                                                               Java Programming     99
   96   97   98   99   100   101   102   103   104   105   106