Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
boolean bln = <value>;
Where value can either be true or false.
Boolean data type is mainly used in conditional statement which enables program to do different things depending upon the value of the variable.
Boolean data type example
- public class FindNumber {
- public static void main(String args[]){
- boolean found = false;
- //number to search
- int find = Integer.parseInt(args[0]);
- //range of numbers
- int range = Integer.parseInt(args[1]);
- for(int i=0; i < range; i++){
- if(i == find){
- found = true;
- break;
- }
- }
- //if number found print message
- if(found){
- System.out.println("Number found in given range.");
- //if number not found
- }else{
- System.out.println("Number not found in given range.");
- }
- }
- }

(No subject)
Post new comment