L
L
Lesha2015-10-11 14:30:18
Java
Lesha, 2015-10-11 14:30:18

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 d2ef6434d0b24173a01d30b7ec1fc17f.pngis 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 84390d89bdfd4eec9f308f15739b5edd.pngNow 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, d54ddf2c896d4c1984da034d133ca4cf.pngbut when compiling it, it displays an error b401dd22e64a41878bd1434e5fa74964.png
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

3 answer(s)
R
RedHairOnMyHead, 2015-10-11
@enempluie

Try an explicit cast to int

M
Maxim Moseychuk, 2015-10-11
@fshp

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"

A
anzufff, 2021-04-19
@anzufff

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 question

Ask a Question

731 491 924 answers to any question