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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.