The if statement executes a block of code only if the specified
expression is true. If the value is false, then the if block is skipped
and execution continues with the rest of the program. You can either
have a single statement or a block of code within an if statement. Note that the conditional expression must be a Boolean expression.
The simple if statement has the following syntax:
SYNTAX:
Syntax : if ( boolean -expression ) { if -code; } rest-of-code; |
FLOWCHART:
EXAMPLE PROGRAM
/* PROGRAM TO FIND THE LARGEST NUMBER*/
public class IfStatementDemo
{ public static void main(String[] args)
{ int a = 10, b = 20; if (a > b) System.out.println("a > b"); if (a < b) System.out.println("b > a"); } }
Output
b > a
No comments:
Post a Comment