Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
Advertisements
