Mega Code Archive

 
Categories / Java Book / 001 Language Basics
 

0046 Simplest if statement

Java has two selection statements: if and switch. Simplest if statement form is shown here: if(condition) statement; condition is a boolean expression. If condition is true, then the statement is executed. If condition is false, then the statement is bypassed. Here is an example: public class Main { public static void main(String args[]) { int num = 99; if (num < 100) { System.out.println("num is less than 100"); } } } The output generated by this program is shown here: num is less than 100