Page 169 - CA_Blue( J )_Class9
P. 169

Statement 1;
                        else
                            Statement 2;
                    }
                    else
                    {
                        if(Condition 3)
                            Statement 3;
                        else
                            Statement 4;
                    }
                                                                Start





                                                true                               false
                                                                if (a>b)



                          true                      false                      true                      false
                                       if (a>c)                                             if (b>c)


                    print a                            print c           print b                            print c






                                                                 Stop
                 Example:

                          int a=8, b=3, c=6;
                        if(a>b)
                            if(a>c)
                            System.out.println(a+" is greatest");
                            else
                                System.out.println(c+" is greatest");
                        else
                            if(b>c)
                                System.out.println(b+" is greatest");
                            else
                                System.out.println(c+" is greatest");
                  Program 8      Input a number and print whether it is greater than 40. If it is greater than 40, then check
                                 whether it is greater than 80.

                   1      import java.util.*;

                   2      class greater_than_40
                   3      {





                                                                                     Conditional Constructs in Java  167
   164   165   166   167   168   169   170   171   172   173   174