Mega Code Archive

 
Categories / Java Book / 001 Language Basics
 

0048 Using a boolean value to control the if statement

The value of a boolean variable is sufficient, by itself, to control the if statement. public class Main { public static void main(String args[]) { boolean b; b = false; if (b) { System.out.println("This is executed."); } else { System.out.println("This is NOT executed."); } } } There is no need to write an if statement like this: if(b == true) ... The output generated by this program is shown here: This is NOT executed.