Skip to content

Instantly share code, notes, and snippets.

@peterdcasey
Created January 30, 2020 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterdcasey/a0652a6fa8df87890176d8941e7c3b22 to your computer and use it in GitHub Desktop.
Save peterdcasey/a0652a6fa8df87890176d8941e7c3b22 to your computer and use it in GitHub Desktop.
/**
* TesterBool
* <br>
* <p>Build a logical expression using True(#) and False(#)
* method calls. Number the T/F calls sequentially, left to right.
* </p>
* <p>The output displays the numbers of the called methods, if
* evaluated, and the final result.
* </p>
* <p>Example: False(1) && (True(2) || False(3)) || True(4)
* </p>
* <p>Output: 1 4 --> true
* </p>
*
* @author Peter
* @version 0.03
*/
public class TesterBool
{
/**
* Main method, add boolean expression here.
*/
public static void main(String[] args) {
boolean expr = true;
//expr = False(1) && (True(2) || False(3)) || True(4) ;
//expr = (True(1) && False(2)) || True(3) ;
expr = False(1) || True(2) && False(3) ;
//expr = !(False(1) && (True(2)) || False(3)) || True(4) ;
System.out.println(" --> " + expr);
}
/**
* Pass true and expression number to display
*/
private static boolean True(int num) {
return showExprNum(true, num);
}
/**
* Pass false and expression number to display
*/
private static boolean False(int num) {
return showExprNum(false, num);
}
/**
* Print expression number and return boolean
*/
private static boolean showExprNum(boolean expr, int exprNum) {
System.out.print(" " + exprNum + " ");
return expr;
}
private TesterBool() {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment