1.7 Control Statement || Decesion Making || if & else statement || if else programming.

Control Statement:

To comtrol of flow of execution.

1. Decesion Statement.
    if statement: to test the condition its test boolean condition (true or false).
    swith statement: to select one of many code block to be executed.


1. If Statement: 

   ->     if(condition) -> expression resulting boolean value.
        {
        -
        - //statement
        }
        if(condition)
        {
        -
        -
        }
        else
        {
        -
        -
        }


   ->     if(condition1)
        {
        -
        -
        }
        else if(condition2)
        {
        -
        -
        }
        else
        {
        -
        -
        }

->    if(condition1)
            {
                if(condition2)
                {
                -
                -
                }
                else
                {
                -
                -    
                }
        }
        else
            {
            -
            -
            }

1. Switch Statement: 

-> switch(expression)
            {
            -
            -
            }


Example Program1:

    class Program1
        {
        public static void main(String args[])
            {
            int num = 2;
            if(num>7)
            {
            System.out.println("number is above 7");
            }
            System.out.println("main method is ended");
            }

        }



Example Program2:

    class Program2
        {
        public static void main(String args[])
            {
            int num = 2;
            if(num>7)
            {
            System.out.println("number is above 7");
            }
            else
                {
                System.out.println("number is bleow 7");
                }
            System.out.println("main method is ended");
            }

        }

Example Program3:

    class Program3
        {
        public static void main(String args[])
            {
            System.out.println("main method is started");
            int num = 7;
            if(num>7)
            {
            System.out.println("number is above 7");
            }
            else if("num==7");
                {
            System.out.println("number is equal to 7");
                }
            else
                {
             System.out.println("number is below 7");
                }
        
            System.out.println("main method is ended");
            }

        }


Example Program4:

    class Program4
        {
        public static void main(String args[])
            {
              Syatem.out.println("main method is started");
            double availBal = 5000.00;
            double amt = 7000.00;
          
            if(amt<availBal)
            {
            System.out.println("withdraw sucess");
            }
            else
            {
             System.out.println("withdraw failed");
            }
            System.out.println("Account balance is ="+availBal);
            System.out.println("main method is ended");
            }

        }

more details follow video given below:









Comments

Popular Posts