Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 876 Bytes

conditionals.md

File metadata and controls

41 lines (31 loc) · 876 Bytes

Java if... else... statement

Java if statement is used to test the condition

// program to check if the age is greater than 18

class conditional{
    public static void main(){
        int age = 20;
        if (age > 18){
            System.out.Println("Age is greater than 18");
        }
    }
}

Write a program to find greatest of two numbers using if...else

// Program to find greatest of two number

class Greater{
    public static void main(String args[]){
        int a = 10;
        int b = 20;
        
        if (a > b){
            System.out.println("a is greater");
        } else {
            System.out.println("b is greater");
        }
    }
}

Programs ToDo

Write a program to find greatest of 3 numbers using nested if...else...

Write a program to find greatest of 3 numbers using else if ladder