Friday, January 4, 2013

IF ELSE STATEMENT

The if/else statement is an extension of the if statement. If the statements in the if statement fails, the statements in the else block are executed. You can either have a single statement or a block of code within if-else blocks. Note that the conditional expression must be a Boolean expression.
The if-else statement has the following syntax:

Syntax :

if(boolean-expression)
{
  if-code;
}
else
{
  else-code;
}
 
rest-of-code;
 
FLOW CHART :
 

EXAMPLE PROGRAM:

/* PROGRAM TO CAN VOTE OR CANNOT VOTE*/

public class vote
 {

	public static void main(String[] args)
         {
		int age=18
		if (age>18) 
                {
			System.out.println("CAN VOTE");
		} 
                else 
                {
			System.out.println("CANNOT VOTE");
		}
	}
}

OUTPUT:

CAN VOTE

1 comment:

Animated Social Gadget - Blogger And Wordpress Tips