Professional Documents
Culture Documents
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:
If else Statement:
import java.util.Scanner;
int i = scr.nextInt();
if(i%2 == 0)
else
{
System.out.println("Given number is odd");
Output:
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