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
thanks for sharing this useful code!!
ReplyDeleteSmith
Quality Web Programmers