CodesJava

Easy learning with example program codes

Boolean Data Type in Java

 
The boolean data type has only two possible values true and false.

Program to declare and use Java primitive boolean variable.

/**
 * Program to declare and use Java primitive boolean variable.
 * @author CodesJava
 */
public class DataTypeBooleanExample {	
  public static void main(String args[]){ 
	//Declare boolean type variables.
	boolean b1 = true;
        boolean b2 = false;
 
        //Use ternary operator to initialise.
        boolean b3 = (13 > 22) ? true : false;
 
        //Print variables value.
        System.out.println("b1 Value :" + b1);
        System.out.println("b2 Value :" + b2);
        System.out.println("b3 Value :" + b3);
  }
}

Output:

b1 Value :true
b2 Value :false
b3 Value :false

 

Please follow and like us:
error
Posted in Java   








Copyright © 2019 CodesJava DMCA.com Protection Status