L
L
Lesha2015-10-16 12:39:05
Java
Lesha, 2015-10-16 12:39:05

How to change the code?

Hello! Let's get to the question. I am learning Java from the book by Herbert Schildt, and now, having approached the next example for testing, I ran into a problem.
Given:
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&q) + "\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&q) + "\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&q) + "\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&q) + "\t" + (p|q) + "\t");
System.out.println((p^q) + "\t" + (!p));
}
}
Required:
Change "false" and "true" to "0" and "1" - that is, instead of "true" and "false" should be "1" and "0"
bd064558902e427387f75c5add2b9b5d.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evgeny Kornachev, 2015-10-16
@enempluie

In theory, it is enough to replace
with
and further in the code in the places of initialization of variables,
replace true with 1, and false with 0

p = 1; 
q = 0;

A
aol-nnov, 2015-10-16
@aol-nnov

Have you already read about data types?

A
abs0lut, 2015-10-16
@abs0lut

Use the ternary conditional operator.
Here is an example of how to replace your boolean variables with int:
Same with expressions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question