Conditions
Java has following conditional statements:
1. if statement
2. nested if statement
3. if-else statement
4. if-else-if statement
5. Switch Case Statement
1. if statement:
Syntax:
if(condition){
Statement(s);
Statement(s);
}
2. Nested if statement:
Syntax:
if(condition_1) {
Statement1(s);
if(condition_2) {
Statement2(s);
}
}
3. if-else statement:
Syntax:
if(condition) {
Statement(s);
}
else {
Statement(s);
}
4. if-else-if statement:
if(condition_1) {
statement(s);
}
else if(condition_2) {
statement(s);
}
else {
statement(s);
}
5. Switch Case:
Syntax:
switch(expression) {
case valueOne:
statement(s)
break;
break;
case valueTwo:
statement(s
break;
default:
statement(s)
Comments
Post a Comment