Conditional Statements
Conditional Statements checks the condition or compares two variables using comparison operators and performs action. It allows you to execute a block of code if a specified condition is true.
If Statement
If statement checks a condition and if it is true, it executes a block of code.
If-else Statement
If-else statement checks a condition and if it is true, it executes a block of code. Otherwise, the code in else block is executed.
Else-if Statement
If we want to check more than one conditions in Java, we can use else-if statements.
Nested if Statements
Nested if statements are if statements within if statements.
Ternary Operator
Ternary operator is used as short hand if-else statement.
Practice Exercises
Complete these exercises to reinforce your learning and earn XP
Sign in to track your progress and earn XP!
Exercise 1 of 2Easy
What is the output when x = 5 in: if(x > 5) print A; else print B;
10 XP~3 min
Exercise 2 of 2Easy
The keyword used for alternative condition is ___.
10 XP~2 min