17 Aug Understanding Boolean Type in Java with examples
Java has 8 Primitive types, including Boolean type. Possible values are TRUE and FALSE. Default is FALSE. Use this to track TRUE/ FALSE record.
Following are some examples to work with Boolean Type in Java:
Example 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public class Main { public static void main(String[] args) { boolean p; p = false; if(p) System.out.println("FALSE"); else System.out.println("TRUE"); } } |
Output
1 2 3 |
TRUE |
Example 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
public class Main { public static void main(String[] args) { boolean p; p = true; if(p) System.out.println("TRUE"); else System.out.println("FALSE"); } } |
Output
1 2 3 |
TRUE |
Example 3
1 2 3 4 5 6 7 8 9 10 11 |
public class Main { static boolean a; public static void main(String[] args) { System.out.println("Default value of boolean Type = " + a); } } |
Output
1 2 3 |
Default value of boolean Type = false |
No Comments