目录

JAVA 如何查找偶数或奇数


检查数字是偶数还是奇数

判断一个数是偶数还是奇数:

示例

int number = 5;

// Find out if the number above is even or odd
if (number % 2 == 0) {
  System.out.println(number + " is even.");
} else {
  System.out.println(number + " is odd.");
}
亲自试一试 »