- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to convert boolean to integer
To convert boolean to integer, let us first declare a variable of boolean primitive.
boolean bool = true;
Now, to convert it to integer, let us now take an integer variable and return a value “1” for “true” and “0” for “false”.
int val = (bool) ? 1 : 0;
Let us now see the complete example to convert boolean to integer in Java.
Example
public class Demo { public static void main(String[] args) { // boolean boolean bool = true; System.out.println("Boolean Value: "+bool); int val = (bool) ? 1 : 0; // Integer System.out.println("Integer value: "+val); } }
Output
Boolean Value: true Integer value: 1
- Related Articles
- Java Program to convert integer to boolean
- Java Program to convert boolean value to Boolean
- Java Program to convert an Integer to a boolean specifying the conversion values
- Java Program to convert String to Boolean
- Java Program to convert Boolean to String
- Java Program to convert integer to octal
- Java Program to convert integer to hexadecimal
- How to convert a Boolean to Integer in JavaScript?
- Convert Java Boolean Primitive to Boolean object
- Java Program to convert from integer to String
- Java Program to convert from String to integer
- Program to convert set of Integer to Array of Integer in Java
- Java Program to convert String to Integer using Integer.parseInt()
- Java Program to convert decimal integer to octal number
- Java Program to convert integer to String with Map

Advertisements