google Ads

Monday, July 13, 2009

If statements

If statements

The if statements is having three types of statements
simple if statements
if-else statements
nested if-else statements

simple if staments
It is used to control the flow of execution of the statements and also used to test logically to find whether the condition is true false.

Syntax:
if (condition)
{
statements 1;
}
statements 2;

If the conditions is true, then the statements 1 will be executed. The true statements may be a single statements or group of statements. If the condition is false then the statements 1 are not executed but statements 2 will be executed.

Example:

if (a>=10)
{
System.out.println(“A is greater than or equal to 10”);
}
System.out.println(“A value is less than 10”);


The above example : the condition is true output will be proved “A is greater than or equal to 10” . If the condition is false output will be proved ”A value is less than 10”.

void main()
{
If(a<=10;
{
System.out.println(“A value is less than or equal to 10 “;
}
System.out.println(“A value is greater then 10”;
}

If a value is 6

The output will be:

Enter the Value A:
6
A value is less than or equal to 10

If a value is 15

The output will be:

Enter the Value A:
15
A value is greater then 10

No comments:

Post a Comment