Page 119 - CA_Blue( J )_Class10
P. 119

11              t = bs + da;
                  12              if(t>20000)

                  13              {
                  14                  tax = 0.05 * t;

                  15              }
                  16              ts = t - tax;

                  17              System.out.println("\tSalary Slip");
                  18              System.out.println("\t-----------");

                  19              System.out.println(" Basic Salary              : "+bs);
                  20              System.out.println(" Dearness Allowance        : "+da);

                  21              System.out.println(" Salary before tax         : "+t);
                  22              System.out.println(" Tax                       : " + tax);
                  23              System.out.println(" Total Salary              : " + ts);

                  24          }

                  25      }
                 You will get the following output:














                 7.2.2 The if…else Statement
                 In some situations, we may require to choose any one of the two actions depending on a condition. In Java, we can
                 implement this functionality in our program by using the if…else statement. The if…else statement allows us to execute
                 one block of code out of two at a time depending on the condition provided. If the condition is satisfied, then the first
                 set of statements will execute, and if it does not satisfy then the set of statements after the else block will execute. The
                 syntax of the if…else statement is:

                    if (condition)
                    {
                        statement 1;
                    }
                    else
                    {
                        statement 2;
                    }
                 Example of the if…else statement is:

                    int a=5, b=2;
                    if(a>b)
                    {


                                                                                                                       117
                                                                                           Conditional Constructs in Java  117
   114   115   116   117   118   119   120   121   122   123   124