|
true or: false |
Problem:
|
|
Therefore: we need to convert the input (ASCII) representation to the internal boolean representation
boolean parseBoolean( String s ): return a boolean value translated from the input string s If s == "true", function returns true (= 1) If s == "false", function returns false (= 0) |
See: click here
Input Output -------- ------------- "true" ---> 00000001 "false" ---> 00000000 Note: "true" means: the ASCII codes 01110100 01110010 01110101 01100101 "false" maens: the ASCII codes 01100110 01100001 01101100 01110011 01100101 |
Example:
boolean x; String input = in.nextLine(); // Read in a string ("true" or "false") x = Boolean.parseBoolean(input); if ( x ) { System.out.println("You have entered the `true' boolean value"); } else { System.out.println("You have entered the `false' boolean value"); } |
How to run the program:
|
The parseBoolean( ) method is just one if-statement that check for the string "true":
public static boolean parseBoolean( String s ) { if ( s.equals("true") ) return true; // returns true, which is the same as the bin number 1 else return false; // returns false, which is the same as the bin number 0 } |
Note:
|
x = BooleanIO.parseBoolean(input); |
Change to Boolean class to BooleanIO
How to run the program:
|