Page 100 - 2617_JSSPS_C-7
P. 100

Start








                                                         Conditional       False
                                                         Expression




                                                                True

                                                          Body of if





                                                            Stop


                                                       Flowchart of 'if' statement

              The syntax of the if statement is as follows:


              if (< conditional expression >)
              {

                  [statements]

              }
                Program 5:  Write a program to execute the statement inside the if block.

              1   public class IfStatement

              2   {

              3       public static void main(int num)

              4       {
              5          System.out.println("Entered number is: " + num);

              6          if (num % 2 == 0)

              7          {

              8          System.out.println("The number is even");

              9          }

              10         System.out.println("Statement outside the if statement");

              11      }

              12  }




                        Premium Edition-VII
                 98
   95   96   97   98   99   100   101   102   103   104   105