Input: boolean = true Output: 1 Input: boolean = false Output: 0
- Get the boolean value to be converted.
- Check if boolean value is true or false
- If 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
true after converting into integer = 1
Example 2: When boolean value is false
false after converting into integer = 0
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.