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
Boolean Type in Java
To display Boolean type, firstly take two variables and declare them as boolean.
boolean val1, val2;
Then one by one assign values to both of them, one of them is shown below −
val1 = true;
Now, use if statement to check and display the Boolean true value.
if(val1)
System.out.println("This is true and will get displayed!");
Let us now see the complete example to work with Boolean Type in Java.
Example
public class Demo {
public static void main(String[] args) {
boolean val1, val2;
System.out.println("Boolean Type in Java");
val1 = true;
if(val1)
System.out.println("This is true and will get displayed!");
val2 = false;
if(val2)
System.out.println("This is false and won't get displayed!");
}
}
Output
Boolean Type in Java This is true and will get displayed!
Advertisements
