Java Program to convert an int to a boolean specifying the conversion values


To convert int to boolean, let us first take the following int.

int one = 1;
int two = 1;
int three = 0;

We have nested if-else statement to display the true or false values. Here, the value “one” is the same as “two” i.e. 1; therefore, the following works −

else if (one.equals(two)) {
   System.out.println(true);
}

The above display “true” and in this way we converted int to boolean.

Let us now see the complete example to learn how to convert int to Boolean.

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      int one = 1;
      int two = 1;
      int three = 0;
      // int to Boolean
      if (one == two) {
         System.out.println(true);
      } else if (one == three) {
         System.out.println(false);
      }
   }
}

Output

True

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 26-Jun-2020

78 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements