Boolean Type in Java

Java 8Object Oriented ProgrammingProgramming

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!
raja
Published on 12-Nov-2018 14:49:52
Advertisements