Notice: Constant WP_MEMORY_LIMIT already defined in /home/javawith/public_html/codesjava.com/wp-config.php on line 107

Notice: Constant WP_MAX_MEMORY_LIMIT already defined in /home/javawith/public_html/codesjava.com/wp-config.php on line 108
Boolean data type in java - CodesJava

CodesJava

Easy learning with example program codes

Boolean Data Type in Java


Notice: Undefined variable: footnotelist in /home/javawith/public_html/codesjava.com/wp-content/plugins/latex2html/inc/core.php on line 475

 
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   

Core Java Tutorial








Copyright © 2019 CodesJava DMCA.com Protection Status