Page 189 - ComputerScience_Class_11
P. 189

2.  if(a%5==0 && a%2==1)
                   {
                       System.out.println("The number is divisible by 5");
                       System.out.println("It is an odd number");
                   }
                   Here, if a%5 returns 0 and a is an odd number, the two messages will be printed.
                 3.  if(c==0)
                   {
                       c=a++ + ++b;
                       System.out.println("c= "+ c);
                   }
                   Here, if c==0, then the value of c will be changed and displayed. However, if c==0 is false, no message will be
                   displayed.

                 if-else Statement
                 Using an if-else statement, either of the two actions will be executed. If the condition is satisfied, then the first part will
                 be executed, else the second part will be executed.
                 Syntax:

                    if(Condition)                                                   True                    False
                                                                                              Condition
                    {                                                                            ?
                        Statement 1;
                                                                             Statement 1                    Statement 2
                    }
                    else
                    {
                        Statement 2;
                                                                                      Flowchart of if-else statement
                    }
                 For example,
                 1.  To check whether the two numbers are equal or not.

                    int a=6, b=7;
                    if(a==b)
                        System.out.println("Numbers are equal");
                    else
                        System.out.println("Numbers are not equal");
                   Here, the output will be: Numbers are not equal
                 2.  To check whether the basic salary is more than 1999, then the tax is 5% of the basic salary else 2.5%.
                    if(basic_sal>=2000)

                        tax= 5.0/100.0*basic_sal;
                    else
                        tax= 2.5/100.0*basic_sal;
                        System.out.println("Tax : "+tax);
                 Here, if the basic salary is greater than or equal to 2000, the tax is 5% of the basic salary else 2.5%.







                                                                                              Statements and Scope  187
   184   185   186   187   188   189   190   191   192   193   194