Go Back   Wiki NewForum | Latest Entertainment News > Career Forum & Tips > Tech Forum & Tutorial > Java Forum & Tutorial


Demonstrate Boolean Values


Reply
Views: 1828  
Thread Tools Rate Thread
  #1  
Old 05-25-2009, 04:30 PM
bholus7
Guest
 
Posts: n/a
Default Demonstrate Boolean Values

Demonstrate Boolean Values

//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 .

Reply With Quote
Reply

New topics in Java Forum & Tutorial





Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
WikiNewForum)