You are on page 1of 3

Roll No: 53

Practical No 3
If Statement:

public class pr3
{  
public static void main(String[] args) 
{  
int age=20;  
        if(age>18)
{   
         System.out.print("Age is greater than 18");  
     }  
}  
}  

Output:

Age is greater than 18

If else Statement:
import java.util.Scanner;

public class pr3

public static void main(String args[])

Scanner scr = new Scanner(System.in);

System.out.print("Enter the number ");

int i = scr.nextInt();

if(i%2 == 0)

System.out.println("Given number is even ");

else

{
System.out.println("Given number is odd");

Output:

Enter the number 20

Given number is even

Nested-If Statement:

public class pr3
{    
public static void main(String[] args) 
{   
     int age=20;  
int weight=80;
if(age>=18)
{    
         if(weight>50)
{  
 System.out.println("You are eligible to donate blood");  
}    
}
System.out.println("You cannot eligible to donate blood");
}
}  
Output:
You are eligible to donate blood

If else If Ladder:

public class pr3 
{
public static void main(String[] args) 
{
int number=-13;    
if(number>0)
{
System.out.println("POSITIVE");  
     }
else if(number<0)
{  
System.out.println("NEGATIVE");  
}
else
{  
System.out.println("ZERO");  
}  
}    
}    
Output:
NEGATIVE

You might also like