Google News
logo
Control Statements in java
Control Statements in java
This involves a kind of decision making to see whether a particular condition has occurred or not and direct the computer to execute certain statements accordingly.
Java Images
1. The if Statement
It is clearly observed that if block is executed only if the condition following if is true.

if (Condition)
{
Statements; /* true block (or) if block */
}
Java Images
if Program using true
class Test 
{ 
public static void main(String[] args)
{ 
if (true) 
{ 
System.out.println("freetmielearn"); 
} 
System.out.println("hi"); 
} 
}
Output :
freetmielearn,hi
if else Statement
It is clearly observed that if block is executed only if the condition following if is true. If the condition is false else block is executed.

if (Condition)
{
Statements; /* true block (or) if block */
}
else
{
Statements; /* false block (or) else block */
}
Java Images