# How Do I Change True False Statements

• 12-16-2013, 04:02 PM
RSdroid
How Do I Change True False Statements
What's up guys. I'm really new to Java and I'm using a self taught book (Java A Beginner's Guide). Basically here I created a truth table for Java's logical operators. My question is how do I get the program to display 1's and 0's rather than true and false? Anyone?

Code:

```class LogicalOpTable {   public static void main(String args[]) {       boolean p, q;       System.out.println("P\tQ\tAND\tOR\tXOR\tNOT");       p = true; q = true;       System.out.print(p + "\t" + q + "\t");       System.out.print((p&g) + "\t" + (p|q) + "\t");       System.out.println((p^q) + "\t" + (!p));       p = true; q = false;       System.out.print(p + "\t" + q + "\t");       System.out.print((p&g) + "\t" + (p|q) + "\t");       System.out.println((p^q) + "\t" + (!p));       p = false; q = true;       System.out.print(p + "\t" + q + "\t");       System.out.print((p&g) + "\t" + (p|q) + "\t");       System.out.println((p^q) + "\t" + (!p));       p = false; q = false;       System.out.print(p + "\t" + q + "\t");       System.out.print((p&g) + "\t" + (p|q) + "\t");       System.out.println((p^q) + "\t" + (!p));```
• 12-16-2013, 04:11 PM
KevinWorkman
Re: How Do I Change True False Statements
Sounds like a job for if statements or ternary operators.
• 12-16-2013, 04:15 PM
gimbal2
Re: How Do I Change True False Statements
Quote:

Originally Posted by KevinWorkman
Sounds like a job for if statements or ternary operators.

or a static utility method that turns a boolean into an int. It all depends on what has already been learned so far. Another answer might be to not want to do this just yet, until more study has been performed.
• 12-16-2013, 04:41 PM
RSdroid
Re: How Do I Change True False Statements
Quote:

Originally Posted by KevinWorkman
Sounds like a job for if statements or ternary operators.

I know a little about if statements but nothing about ternary operators

Quote:

Originally Posted by gimbal2
or a static utility method that turns a boolean into an int. It all depends on what has already been learned so far. Another answer might be to not want to do this just yet, until more study has been performed.

I tried to figure out myself how to turn a boolean into an int and don't seem to get the concept yet. I'm going to try and figure this out once more before giving up on this and probably rereading that chapter.
Thanks to both!
• 12-16-2013, 04:50 PM
RSdroid
Re: How Do I Change True False Statements
I seem to come to a stand still with the operator !
This is what I'm doing.
Code:

```class LogicalOpTable {   public static void main(String args[]) {         int p, q;         System.out.println("P\tQ\tAND\tOR\tXOR\tNOT");         p = 1; q = 1;       System.out.print(p + "\t" + q + "\t");       System.out.print((p&g) + "\t" + (p|q) + "\t");       System.out.println((p^q) + "\t" + (!p));```
• 12-16-2013, 04:53 PM
gimbal2
Re: How Do I Change True False Statements
Yes, the not operator only works on a boolean and now you've turned it into integers. You can't do it like this.

What you have here is a classic example of confusing data for the presentation of data. They are NOT the same. You want booleans in your code to do your operations on, but you want to PRINT an integer as the result.