//demonstrate boolean values.
class BoolTest {
public static void main(String args[]) {
boolean b;
b=false;
System.out.println("b is "+b);
b=true;
System.out.println("b is "+b);
//a boolean value can control the if statement
if(b) System.out.println("this is xecuted");//i.e.
if b is true
b=false;
if (b)System.out.println("this is not xecuted");
//outcome of a relational operator is a boolean
value
System.out.println("10 > 9 is " +(10>9));
}
}
The output generated by the program is :
b is false
b is true
this is xecuted
10 > 9 is true
Normal Termination
Output completed (4 sec consumed).
Few things to note in the above example :
When a boolean value is outputted by println () , true or false
is displayed .
The value of a boolean variable is sufficient , by itself , to control the if statement .
The outcome of a relational operator is a boolean value .
This is why the expression 10 > 9 displays the value true .
Quick Links:
Have Java Problem
Do you have
a Java Question?
Java Books
Java Certification, Programming,
JavaBean and Object Oriented Reference Books
Best Regards,
Java Programming Hints and Tips
All the site contents are Copyright © www.sap-img.com
and the content authors. All rights reserved.
All product names are trademarks of their respective
companies.
The site www.sap-img.com is not affiliated with or endorsed
by any company listed at this site.
Every effort is made to ensure the content integrity.
Information used on this site is at your own risk.
The content on this site may not be reproduced
or redistributed without the express written permission of
www.sap-img.com or the content authors.