Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.726 :

Posted: Mon May 07, 2012 12:59 pm
by atheedom
The answer to question 726 says "& can have integral as well as Boolean operands". I don't understand how this can be true. Would you show me an example. Thanks.

Re: About Question com.enthuware.ets.scjp.v6.2.726 :

Posted: Mon May 07, 2012 3:42 pm
by admin
Example for boolean operands:

Code: Select all

boolean b1 = true;
boolean b2 = true;
boolean b = b1 & b2;
if(b){
   System.out.println("hello");      
}
Example for integral operands:

Code: Select all

  int i1 = 10;
 char c = 'a';
 int k =  i1 & c;
 System.out.println(k);      
HTH,
Paul.

Re: About Question com.enthuware.ets.scjp.v6.2.726 :

Posted: Thu May 18, 2023 7:43 am
by Val Martinez
The explanation

"^ is bitwise xor operator that performs an "xor" (aka exclusive or, in which, the result is 1 only if exactly one of the two operands is 1)"

is not correct.

XOR returns 1 if the bits compared are differents and 0 if are the same.

For example:

int y = 3;//11
int x = 3;//11
int z = y^x;
System.out.println(z);//prints 0

Please, fix it. Thank you.

Re: About Question com.enthuware.ets.scjp.v6.2.726 :

Posted: Fri May 19, 2023 4:00 am
by admin
The explanation is correct. You are also saying the same thing but in different words. When you have exactly one of two digits as 1, then, obviously, the two digits will be different.

Re: About Question com.enthuware.ets.scjp.v6.2.726 :

Posted: Sat Jun 24, 2023 4:58 am
by cristibctr
I'm not saying it's wrong but I genuinely thought the '& can have integral as well as boolean operands.' answer was refering to the calculus 'Integral' and trying to check if the reader is paying close attention to the answers so I didn't choose it. Could it please be changed to integer as that's what the java type is called?

Re: About Question com.enthuware.ets.scjp.v6.2.726 :

Posted: Sat Jun 24, 2023 6:24 am
by admin
This is official terminology as used by the Java Language Specification. See attached screen shot please.
test.png
test.png (103.66 KiB) Viewed 2166 times