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.");
}
尝试一下 »
找出数字是偶数还是奇数
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.");
}
尝试一下 »
If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]
If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]