|
true or: false |
Problem:
|
|
Therefore: we need to convert the internal boolean representation to their (ASCII) representation for output operation also
String toString( boolean x ): return a String that represents the boolean value x If x == true, we return the string "true" If x == false, we return the string "false" |
See: click here
The method toString( ) performs the following translation:
Input Output ---------- ------------- 00000001 ---> "true" 00000000 ---> "false" Note: "true" means: the ASCII codes 01110100 01110010 01110101 01100101 "false" maens: the ASCII codes 01100110 01100001 01101100 01110011 01100101 |
boolean x = true; boolean y = false; String s; s = Boolean.toString(x); // Change to BooleanIO to use my own System.out.println("String for 'true' boolean value = " + s); s = Boolean.toString(y); // Change to BooleanIO to use my own System.out.println("String for 'false' boolean value = " + s); |
How to run the program:
|
This is what the toString( ) method look like:
public static boolean toString( boolean x ) { if ( x == true ) return "true"; // This is a String (= 4 ASCII codes !) else return "false"; // This is a String (= 5 ASCII codes !) } |
Note:
|
Change Boolean to BooleanIO first !
How to run the program:
|