一、常规取模法
int c = 8 ;
if (c%2==0) {
System.out.println(c+"为偶数");
}else {
System.out.println(c+"为奇数");
}
二、使用位运算符>> <<
int c = -8;
if (c == c >> 1 << 1) {
System.out.println(c + "为偶数");
} else {
System.out.println(c + "为奇数");
}
原文:https://www.cnblogs.com/flywithme/p/11037225.html