//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 .
No comments:
Post a Comment