# Thread: How Do I Change True False Statements

1. Member
Join Date
Dec 2013
Posts
3
Rep Power
0

## 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?

Java 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));```

2. ## Re: How Do I Change True False Statements

Sounds like a job for if statements or ternary operators.

3. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## Re: How Do I Change True False Statements

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.

4. Member
Join Date
Dec 2013
Posts
3
Rep Power
0

## Re: How Do I Change True False Statements

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

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!

5. Member
Join Date
Dec 2013
Posts
3
Rep Power
0

## 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.
Java 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));```

6. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

## 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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•