5.1.The if Statement #

if Statements

The if statement is the most basic of all the control flow statements, the statements will execute when the condition checked true.

Syntax 1: One Statement without opening brace and closing brace

if (Expression)

Statement 1;

Example 1:

if (score>=50)

System.out.println(“Passed”);

Syntax 2: More than one Statements must be using with opening brace and closing brace

if (Expression)

{

Statement 1;

Statement 2;

Statement 3;

Statement N;

}

Example 2:

if (score<50)

{

System.out.println(“Failed”);

System.out.print(“Sorry !!!”);

}

Suggest Edit