Page 160 - CA_Blue( J )_Class9
P. 160

•  if-else-if statement
                  •  Nested if statement
                  Let us see them in detail.

                  if statement
                  This is used to handle situations where there is a single condition. If the condition satisfies, the block will execute,
                  otherwise will be ignored.
                  Syntax:
                      if(condition)
                      {
                         Statements;
                      }
                                                  Start



                                               Enter the
                                              person's age





                                                                   true     Display "You are eligible
                                              Is age >= 18?
                                                                                  to vote"

                                              false

                                           Display "You are not
                                             eligible to vote"




                                                  Stop
                  Example 1:

                      if (a==b)
                         {
                             System.out.println("Result : "+(a+b));
                         }
                  Example 2:
                      if(age>=18)
                         {
                             System.out.println("Can give vote");
                         }

                   Program 2      Write a Java program to get a number from the user and display whether it is positive. Also
                                  check whether it is an even number or not.
                     1     import java.util.*;
                     2     class check_positive

                     3     {
                     4         public static void main()




                   158    Touchpad Computer Applications-IX
   155   156   157   158   159   160   161   162   163   164   165