Page 162 - CA_Blue( J )_Class9
P. 162

Example:
                         if(marks>=90)
                             System.out.println("Point 1");
                         else
                             System.out.println("Point 2");


                         <60                          C
                   Program 3      Write a program to input the age of a player and print whether the player can play in an
                                  under-19 tournament or not.
                     1     import java.util.*;
                     2     class age_check

                     3         {
                     4             public static void main ()

                     5             {
                     6                 Scanner sc= new Scanner (System.in);

                     7                 int age;
                     8                 System.out.print("Enter the age of a player : ");

                     9                 age = sc.nextInt();
                    10                 if(age<19)

                    11                 {

                    12                  System.out.println("The player can play the tournament as his age
                               is:  "+ age);
                    13                 }

                    14                 else

                    15                 {
                    16                   System.out.println("The player cannot play the tournament as his
                               age is:  "+ age);
                    17         }

                    18     }}

                  You will get the following output:













                  Multiple if statements
                  Many programs need to check all the conditions as more than one conditions may be satisfied. Here, if the 1st
                  condition satisfies, then statement 1 will be executed. If the 2nd condition satisfies, then statement 2 will be
                  executed. And so on, thus executing all the conditions.



                   160    Touchpad Computer Applications-IX
   157   158   159   160   161   162   163   164   165   166   167