If statement

if statement is used to execute statement on the successful evaluation of specified condition. Syntax of if statement is same as in c or c++. The only difference is that in java condition statement returns boolean data type.


Syntax:

	if( condition_statement )
Statement_1;

if condition specified is true then statement_1 will be executed. Statement written immediately after if statement considered body of if statement. In case if you want to write more statement for if's body then curly braces has to be used.


Syntax:

	if( condition_statement )
{
Statement_1;
Statement_2;
Statement_3;
}

All three statements will be executed if condition_statement is true. if statement following ';', considered without body or null body if statement.


Syntax:

	if( condition_statement ) ;
	
    


Example:


	//file:ifstate.java
//www.jgyan.com
class ifstate
{
public static void main(String arg[])
{
int a=10;
if(a<20)// Single statement in body
System.out.println("a is less than 20");

if(a%2==0) // multi statements in body
{
System.out.println("a is even number");
System.out.println("a is integer");
}
if(a>4) ; // null body or without body
}
}
/*output
a is less than 20
a is even number
a is integer
*/