Sunday, 29 January 2017

Decision Making and Branching Conditional (Decision Making) Statements

Conditional (Decision Making) Statements
In many situations we need to change the order of execution of statement based on some condition. This involves decision making to see whether a particular condition has arrived or not and then direct the computer to execute statements on the basis of the condition.
If Statement
If statement is used to control the flow of execution of the statements. General syntax of if statement is
If (test condition)
{          // Statement block starts here
            Statement a;
            Statement b;
            …………………
}          // Statement block finishes here
            Statement p;
            Statement q;
If the test condition is true then statement block of if statement will be executed otherwise if statement will be skipped and execution will jump to statement p.
Example:
public class IfStatement {
       public static void main(String[] args)
        {
              int marks=70;
             
              if(marks>60)
              {
                     System.out.println(" First Division");
              }
        }
}
The output of this program is:

First Division

No comments: