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

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 12-Nov-2018 10:28:23
Advertisements