Lec : 10 | JAVA

    

LEC:10

If- else conditions in JAVA



         


Source Code:
package lec_5;
import java.util.*;
public class Lec_5 {
public static void main(String[] args) {
//        Synatx of if-else statements
//        if( condition )
//        {
//            statements.......
//        }
//        else
//        {
//            statements.......
//        }
        //        ==,!=,>,<,>=,<=
        System.out.println("Enter your age : ");
        Scanner O1=new Scanner(System.in);
        int age=O1.nextInt();
        if(age<18)
        {
            if(age >10)
            {
                System.out.println("Your age is greater than 10");
            }
            else
                
            System.out.println("Your age is smaller than 10");
            
        }
        else if(age==18)
        {
            System.out.println("your age is 18 !!");
        }
        else
            
            System.out.println("You are eligible for voting !!");
//ternary operators ? : 
// variable=(condition)? Expression_true : Expression _flase ;
//int a=90,b=77;
//int c=(a>b)? a:b;
//System.out.println("The greatest number is : "+c);

    }

}

Comments

Popular posts from this blog

RunwayWithCode

web development Lectures

C++ Lectures