Java Program to convert integer to boolean
Given a integer value, the task is to convert this integer value into a boolean value in Java.
Examples:
Input: int = 1 Output: true Input: int = 0 Output: false
Approach:
- Get the boolean value to be converted.
- Check if boolean value is true or false
- If the integer value is greater than equal to 1, set the boolean value as true.
- Else if the integer value is greater than 1, set the boolean value as false.
Example 1:
// Java Program to convert integer to boolean public class GFG { public static void main(String[] args) { // The integer value int intValue = 1; // The expected boolean value boolean boolValue; // Check if it's greater than equal to 1 if (intValue >= 1) { boolValue = true; } else { boolValue = false; } // Print the expected integer value System.out.println( intValue + " after converting into boolean = " + boolValue); } } |
chevron_right
filter_none
Output:
1 after converting into boolean = true
Example 2:
// Java Program to convert integer to boolean public class GFG { public static void main(String[] args) { // The integer value int intValue = 0; // The expected boolean value boolean boolValue; // Check if it's greater than equal to 1 if (intValue >= 1) { boolValue = true; } else { boolValue = false; } // Print the expected integer value System.out.println( intValue + " after converting into boolean = " + boolValue); } } |
chevron_right
filter_none
Output:
0 after converting into boolean = false
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
Recommended Posts:
- Java Program to convert boolean to integer
- Program to Convert Set of Integer to Array of Integer in Java
- Program to Convert Set of Integer to Set of String in Java
- Program to convert set of String to set of Integer in Java
- Program to convert List of String to List of Integer in Java
- Program to convert List of Integer to List of String in Java
- Convert Double to Integer in Java
- Java Guava | Booleans.indexOf(boolean[] array, boolean target) method with Examples
- Java Guava | Booleans.indexOf(boolean[] array, boolean[] target) method with Examples
- Java Program to Count set bits in an integer
- Java Program to Print a Square Pattern for given integer
- Program to convert Array to Set in Java
- Java program to convert Currency using AWT
- Program to Convert List to Map in Java
- Program to Convert Set to List in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

