This statement helps in choosing one set of statement out of two sets depending on the validity of the logical expression included. It is also known as conditional branch statement as it is used to route program execution through two different paths.
if (logical expression)
If the expression in the parentheses evaluates to true, then if section is executed and if the expression evaluates to false, then else section is executed. Else section is optional.
/* Enter marks and print first div if marks >=60 otherwise print second division. */
public static void main(String args)
BufferedReader k=new BufferedReader(new InputStreamReader
System.out.print("Enter marks : ");
User is asked to enter a value which is stored into an integer variable m. If the value entered in m is greater then or equal to 60, control will execute if section displaying "First Division" on the screen and in case the value in variable m is less then 60, control will execute else section.