If else statement in Java
If else statement in Java:- In this tutorial is explain about how to use if else conditions statements with explanation and given example of Java Programming.
If else Statement:- If statement is conditional branch statement. Its can be used to program execution through two different paths. If statement closed with curly braces. The conditions return a Boolean value.
Syntex:-
If(condition){
// If condition is true then execution
this part of program
}else{
// If
condition is false then execution this part of program
}
Most Read:- What is looping ? How many types of loop in Java and describe?
Example:-
1. If condition is true then:-
int a=10;
int b= 6;
if(a>b){
System.out.println(“a
is greater then b”);
}else{
System.out.println(“a
is smaller then b”);
}
Output:- a is greater then b
2. If condition is false then:-
int
a=10;
Int b= 6;
if(a<b){System.out.println(“a is greater then b”);
}
else{System.out.println(“a is smaller then b”);
}
Output:- a is smaller then b
Nested
If….else if :-
Example:-
if(condition){
System.out.println(“ if condition is true”);
}
else if(a>b){
System.out.println(“(“ if condition is true”);
}else{// if both condition is false then execute this statements
System.out.println(“Both condition is not true”);
0 Comments
Hello Friends, Please comment and share and do not write spam messages