/**
* 检查一个数是否是偶数。
* 读入一个整数:
* 检查它是不是偶数。
*/
package Test;
import java.util.Scanner;
public class T32Scanner {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
int number = input.nextInt();
System.out.println(
(number % 2 == 0)
? "'One' Is " + number + " an even number? true"
: "'One' Is " + number + " an even number? false");
// if (number % 2 == 0)
// System.out.println("Is " + number + " an even number? ture");
// else
// System.out.println("Is " + number + " an even number? false");
boolean even = (number % 2 == 0);
System.out.println("'Two' Is " + number + " an even number? " + even);
}
}
第3章:检查一个数是否是偶数
最新推荐文章于 2024-08-19 16:01:20 发布