OOP IN JAVA -( CONDITIONS - if | else | else if)

java in mainly contain three types of Conditions
        1. if Condition
        2. else Condition
        3. else if Condition 

 If  Condition 

The condition after evaluation of if-statement will be either true or false. And also the if statement in Java accepts Boolean values and if the value is true then it will execute the block of statements under it.


important Note ;
 If we do not provide the curly braces ‘{‘ and ‘}’ after if( condition ) then by default if statement will consider the immediate one statement to be inside its block. 

Ex :-   

                                       public Class IFstatment{
                                  public static void main (string [] args)  {
                                         int s = 16;

                                       if  ( s<16) {
                                                  system .out.println  (" hi");
                                             }
                                      }
                              }


else Condition

Use the else statement to specify a block of code to be executed if the condition is false. 
                                



Ex -              public Class IFstatment{
                                  public static void main (string [] args)  {
                                         int s = 35 ;

                                       if  ( s<16) {
                                                  system .out.println  (" hi");
                                             } else {
                                                  system .out.println  (" Bye");  

                                      }
                              }

else if Condition 

 when you Use the else if statement to specify a new condition if the first condition is false.





              Ex :-                public Class IFstatment{
                                              public static void main (string [] args)  {
                                                   int s = 35 ;

                                                    if  ( s<16) {
                                                  system .out.println  ("hi");
                                             } else if ( s< 22) {
                                                  system .out.println  ("come");  
                                             }else {
                                                  system .out.println  (" Bye"); 
                                             }
                                       }
                                }

THANK YOU!


Comments

Popular posts from this blog

DEMYSTIFYING THE POWER OF x86 ARCHITECTURE

A GUID TO BEACOMING A SOFTWARE ENGINEER

JAVA LAMBDA EXPRESSION