Answer the question
In order to leave comments, you need to log in
Boolean = 0, 1; How to set the boolean value True to zero and False to one?
I'm studying Java according to the book by Herbert Schildt, on the screen there is a script that reproduces a table with the results of "frauds" of logical operators with changing values of the variables Q and P of the boolean type. The table is compiled Now you need to do the same, only the variables Q and P are replaced by 0 and 1 ... How to do this? I tried to assign it as a regular variable, but when compiling it, it displays an error
People, help me, it would be nice to figure it out myself, but something doesn’t work out very well ...
Answer the question
In order to leave comments, you need to log in
1) No one is interested in your screenshots. I can't even copy-paste to show the error.
2) No need to rename variables p and q to 0 and 1. Variable names in java cannot start with numbers.
3) "How to set the logical value True to zero, and False to one?" Vice versa. False is equivalent to zero. True is equivalent to everything else.
4) The first link in Google for "java boolean to int"
i tried with for, created int
for (count = 0; count < 1; count++) {
System.out.print(((p) ? 1 : 0) + "\t" + ((q) ? 1 : 0) + "\t");
System.out.print(((p & q) ? 1 : 0) + "\t" + ((p | q) ? 1 : 0) + "\t");
System.out.println(((p ^ q) ? 1 : 0) + "\t" + ((!p) ? 1 : 0));
}
spied a little, plus changed
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question