About Question com.enthuware.ets.scjp.v6.2.726 :
Moderator: admin
-
- Posts: 2
- Joined: Sat Apr 21, 2012 12:05 pm
- Contact:
About Question com.enthuware.ets.scjp.v6.2.726 :
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.
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.726 :
Example for boolean operands:
Example for integral operands:
HTH,
Paul.
Code: Select all
boolean b1 = true;
boolean b2 = true;
boolean b = b1 & b2;
if(b){
System.out.println("hello");
}
Code: Select all
int i1 = 10;
char c = 'a';
int k = i1 & c;
System.out.println(k);
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 11
- Joined: Thu Sep 01, 2022 10:58 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.726 :
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.
"^ 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.
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.726 :
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.
If you like our products and services, please help us by posting your review here.
-
- Posts: 6
- Joined: Sun Jun 18, 2023 11:03 am
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.726 :
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?
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.726 :
This is official terminology as used by the Java Language Specification. See attached screen shot please.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 145 guests