Boolean Type in Java


To display Boolean type, firstly take two variables and declare them as boolean.

boolean val1, val2;

Then one by one assign values to both of them, one of them is shown below −

val1 = true;

Now, use if statement to check and display the Boolean true value.

if(val1)
System.out.println("This is true and will get displayed!");

Let us now see the complete example to work with Boolean Type in Java.

Example

 Live Demo

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 true and will get displayed!");
      val2 = false;
      if(val2)
      System.out.println("This is false and won't get displayed!");
   }
}

Output

Boolean Type in Java
This is true and will get displayed!

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

12K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements