Java Learning Made Easy by Dheeraj Mehrotra - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

IF– ELSE Statement

01855.jpg01856.jpg01857.jpg

This conditional control statement of Java conducts the execution of the

01858.jpg

statement if the condition is true and conducts other specified execution

01859.jpg

if the condition is false. It consists of an if statement, followed by a

01860.jpg

statement or block of statements, followed by the keyword else, followed

01861.jpg

by another statement or block of statements. It has the following syntax :

01862.jpg01863.jpg01864.jpgif (expression)

 

01865.jpg01866.jpg01867.jpg01868.jpg

statement 1;

01869.jpg01870.jpg

else

01871.jpg01872.jpg

statement 2;

01873.jpg01874.jpg01875.jpg01876.jpg

If the expression is true, the statement 1 is executed otherwise the

01877.jpg

statement 2 is executed. The statement 1 and statement 2 can be a

01878.jpg

single statement or a block/compound statements.

01879.jpg01880.jpg01881.jpg01882.jpgattention@computerscienceexpertise.com

 

01883.jpg01884.jpg01885.jpg01886.jpg01887.jpg01888.jpg01889.jpg01890.jpg01891.jpg01892.jpg01893.jpg01894.jpg01895.jpg01896.jpg01897.jpg01898.jpg01899.jpg01900.jpg01901.jpg01902.jpg01903.jpg01904.jpg01905.jpg