& symbol in php equivalent in Java
Can the following
<?=($Num&1) ? "odd" : "even"?开发者_高级运维>
translate to an equivalent in Java?
String s = (num % 2 == 0) ? "even" : "odd";
To be thorough, that isn't the same operator that you're using (bitwise AND). Bitwise AND is the same in java, so you could also write your php line like:
String s = (num & 1 == 0) ? "even" : "odd";
A direct translation would be:
string s = ( num & 1 != 0 ) ? "odd" : "even"
* note: not entirely sure if the !=0
part is strictly necessary.
精彩评论