English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
To display the boolean type, first use two variables and declare them as boolean values.
boolean val1, val2;
Then assign values to them one by one, as shown below-
val1 = true;
Now, use the if statement to check and display the boolean value true.
if(val1) System.out.println("This is correct and will be displayed!");
Now let's look at a complete example to use the boolean type in Java.
public class Demo { public static void main(String[] args) { boolean val1, val2; System.out.println("Boolean Type in Java"); val1 = true; if(val1) System.out.println("This is correct and will be displayed!"); val2 = false; if(val2) System.out.println("This is false and won't get displayed!"); } }
Output Result
Boolean Type in Java This is correct and will be displayed!