Java Program to convert integer to boolean


To convert integer to boolean, firstly let us initialize an integer.

int val = 100;

Now we will declare a variable with primitive boolean. While declaration, we will initialize it with the val value comparing it with an integer using the == operator. If the value matches, the value “True” is returned, else “False” is returned.

boolean bool = (val == 100);

Let us now see the complete example displaying how to convert integer to boolean.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      int val = 100;
      System.out.println("Integer: "+val);
      boolean bool = (val == 100);
      System.out.println("Converted to Bool: "+bool);
   }
}

Output

Integer: 100
Converted to Bool: true

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

10K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements