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
Updated on: 2020-06-26T10:12:14+05:30

137 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements