Previous Code:-
if decision making statement
List Code:-
Java codes
Next Code:-
Nesting of if-else statement
Java Programs:-
List of Java Programs
if decision making statement
List Code:-
Java codes
Next Code:-
Nesting of if-else statement
Java Programs:-
List of Java Programs
The if – else statement is an extension of the simple if statement.
Syntax:-
if(condition)
{
True - Block of Statement
}
else
{
false - Block of Statement
}
Statement;
Note:-
# Condition can be expression or relation.
# If body of statement is only one statement than braces ({}) are not needed.
# Body of the statement may have one or more statement.
# Either true – block of statement or false – block of statement is executed, not both.
Execution:-
If condition is true than true - block of statement is executed otherwise false - block statement is executed than control is moved to statement next to if statement.
Example:-
Program to find Greatest number between 2
import java.util.Scanner;
class group{
public static void main(String arg[]){
int num1, num2;
Scanner grest = new Scanner(System.in);
System.out.println("Enter 1st number");
num1 = grest.nextInt();
System.out.println("Enter 2nd number");
num2 = grest.nextInt();
if(num1 < num2)
System.out.println("Greatest number"+num1);
else
System.out.println("Greatest number"+num2);
}
}
Leave reply
Add your comments here