Thursday, September 4, 2025
HomeLanguagesJavaJava Program to convert integer to boolean

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);
    }
}


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);
    }
}


Output:

0 after converting into boolean = false
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6632 POSTS0 COMMENTS
Nicole Veronica
11800 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11859 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS