English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
To convert int to boolean, let's first get the following int.
int one = 1; int two = 1; int three = 0;
We have nested if-The else statement is used to display true or false values. Here, the value is 1is equal to 2is the same, that is1; Therefore, the following work-
else if (one.equals(two)) { System.out.println(true); }
The display above is 'true', so we convert int to boolean.
Now let's look at the complete example to understand how to convert int to Boolean.
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 Result
True