Java Program to convert int to boolean without specifying boolean type

Let’s say we have initialized two int variables and want to convert them to boolean. Following are our integers:

int a = 1;
int b = 0

Now, we will compare the integers a and b as in the example below:

Example

public class Main {

  public static void main(String[] args) {
   
    int a = 1;
    int b = 0;
    
    if(a == b) {
         System.out.println(true);
    }
    
    else {
        System.out.println(false);
    }
  }
}

Output

false
Java Program to convert integer to boolean
Java Program implementing XOR on a set of Booleans
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment