If Else Statement in Java
If Else Statement in Java
JAVA
If else statement can be followed by an optional
ELSE statement, which execute when the
boolean expression is false.
SYNTAX:
The syntax of an if else:
if (boolean_expression){
//Execute when the boolean expression is
true
}else{
//execute when the boolean expression is
false
}
SYNTAX:
if (boolean_expression 1 ){
//Execute when the boolean expression 1 is true
}else if (boolean_expression 2){
//Execute when the boolean expression 2 is true
}else if (boolean_expression 3){
//Execute when the boolean expression 3 is true
}else {
//Execute when the none of the above condition is
true.
}
EXAMPLE:
public class test {
public static void main (string args[]){
int x = 30;
if ( x == 10 ){
system.out.print( value of x is 10);
}else if ( x == 20 ) {
system.out.print( value of x is 20);
}else if ( x == 30 ) {
system.out.print( value of x is 30);
}else {
system.out.print(this is else statement);