IF ELSE control Statement

Understanding the "if else" Control Statement in Java

Control statements are an essential part of programming languages and play a crucial role in determining the flow of execution in a program. The "if" statement allows programmers to specify a condition that, if true, will execute a block of code. if the if condition is false then else block is executed

Basic Syntax of the "if else" Statement

The basic syntax of the "if" statement in Java is as follows:


if (condition) { // code block to be executed if the condition is true
} else{ // code block to be executed }

The "condition" in the above syntax is a Boolean expression that evaluates to either true or false. For example, consider the following code snippet:

if (x > 5) {
// code to be executed if x is greater than 5
// code to be executed if the condition is true
}
else{

// code to be executed if x is less than 5
// code to be executed if the condition is false
}

Example Program to demonstrate if else control statement

Program to find given number is even or odd using if control statement


Output 1


Output 2