Java Program to convert boolean to integer Last Updated : 25 Apr, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report Given a boolean value, the task is to convert this boolean value into an integer value in Java. Examples: Input: boolean = true Output: 1 Input: boolean = false Output: 0 Approach: Get the boolean value to be converted.Check if boolean value is true or falseIf the boolean value is true, set the integer value as 1.Else if the boolean value is false, set the integer value as 0. Below is the implementation of the above approach: Example 1: When boolean value is true Java // Java Program to convert boolean to integer public class GFG { public static void main(String[] args) { // The boolean value boolean boolValue = true; // The expected integer value int intValue; // Check if it's true or false if (boolValue) { intValue = 1; } else { intValue = 0; } // Print the expected integer value System.out.println( boolValue + " after converting into integer = " + intValue); } } Output:true after converting into integer = 1 The time complexity is O(1), which means it will take a constant amount of time to execute, regardless of the input size. The auxiliary space used by the program is also constant. Example 2: When boolean value is false Java // Java Program to convert boolean to integer public class GFG { public static void main(String[] args) { // The boolean value boolean boolValue = false; // The expected integer value int intValue; // Check if it's true or false if (boolValue) { intValue = 1; } else { intValue = 0; } // Print the expected integer value System.out.println( boolValue + " after converting into integer = " + intValue); } } Output:false after converting into integer = 0 Comment More infoAdvertise with us Next Article Java Program to Convert Boolean to String C code_r Follow Improve Article Tags : Java Java Programs Practice Tags : Java Similar Reads 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, 2 min read Java Program to Convert Char to Int Given a char value, and our task is to convert it into an int value in Java. We can convert a Character to its equivalent Integer in different ways, which are covered in this article.Examples of Conversion from Char to Int:Input : ch = '3'Output : 3Input : ch = '9'Output : 9The char data type is a s 4 min read Java Program to Convert String to boolean In Java, to convert a string to a Boolean, we can use Boolean.parseBoolean(string) to convert a string to a primitive Boolean, or Boolean.valueOf(string) to convert it to a Boolean object. The Boolean data type only holds two possible values which are true and false. If the string equals "true" (ign 3 min read Java Program to Convert Boolean to String In Java programming, you might come across the need to convert a simple "true" or "false" boolean value into a String. It may seem like a challenging task, but fear not! In this article, You will explore some methods to convert a boolean value to a string in Java Method for Boolean to String Convers 4 min read Java Program to Convert Integer Values into Binary Given an integer in Java, your task is to write a Java program to convert this given integer into a binary number. Example: Input: = 45 Output: = 101101 Input: = 32 Output: = 100000 Integers: Integers are numbers whose base value is 10. The Integer or int data type is a 32-bit signed twoâs complemen 4 min read Java Program to Convert Int to Double Java data types can be categorized as primitive and non-primitive. Primitive data types contain a single value, whereas non-primitive data types contain an address of the variable value. Java supports 7 primitive data types - boolean, byte, char, short, int, long, float, and double. These data types 4 min read Like