Page 173 - Cs_withBlue_J_C11_Flipbook
P. 173

System.out.println("Grade C");
                   System.out.println("Grade Obtained");
                   Here, if the value of variable a is greater than 89, Grade A will be printed . If a is greater than 79 but less than 90,
                   then Grade B will be printed otherwise Grade C will be printed. The message “Grade Obtained” will be printed in
                   each case.
                 2.  if(a>=0 && a<=20)
                     System.out.println("From 0 to 20");
                   else if(a>=21&& a<=40)
                     System.out.println("From 21 to 40");
                   else
                     System.out.println("More than 40");
                   Here, depending on the value stored in variable a, the corresponding message will be printed on the basis of the
                   given conditions.

                 nested if statement
                 When an if statement is placed inside another if statement, then it is known as a nested if statement.
                 Syntax:

                    if(Condition1)
                    {
                        if( Condition2) //nested
                        {
                            Statement1;
                        }
                        else
                        {
                            Statement2;
                        }
                    else
                    {
                        if(Condition3)
                        {
                            Statement3;
                        }
                        else
                        {
                           Statement4;
                        }
                    }
                 Flowchart:

                                                   Yes                           No
                                                             Condition 1




                                 Yes                     No                  Yes                     No
                                         Condition 2                                 Condition 3



                            Statement 1               Statement 2       Statement 3                Statement 4




                                                                                                                       171
                                                                                                 Statements and Scope  171
   168   169   170   171   172   173   174   175   176   177   178