If Else Statement

Syntax:-

if(test expression){
        True-block statement(s)
}
else{
        False-block statement(s)
}
statement-X
  • If the test expression is true, then the true-block statement(s) is executed , otherwise false-block statement(s) are executed.
  • In either case , either true-block or false block will be executed , not both.
  • In both the cases , the control is transferred subsequently to the statement-x.
  • Any one of the following comparison operator may be used to form test expression. ( < , > , != , == , <= , >= )
  • Example:-
int a = 30;
if ( a < 16 ){
       System.out.println("Too Young");
}else{
       System.out.println("Welcome !");
}
  • Output :- Welcome !