A tertiary expression is evaluated like so:
(logical expression) ? (value if true) : (value if false)
So given your values of p and q, you can use them each with an expression such as
p ? 1 : 0
q ? 1 : 0
Tertiary expressions can be used most anywhere that a variable could be used, though in many cases you will need to surround them with parens to force evaluation before the rest of the expression. Example:
p = false; q = false
System.out.print((p ? 1 : 0) + "\t" + (q ? 1 : 0) + "\t");
I am not necessarily saying that is the best way to accomplish changing your program to use 1 and 0 instead of true and false, but tertiary expressions are a way to return 2 different values based upon a logical expression.