package com.example.practice;
import java.util.Scanner;
//判断输入的数字是否为偶数
public class Test1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入一个整数:");
//hasNextInt()判断是否为数字
if (scanner.hasNextInt()) {
//scanner.nextInt()将输入的数据转为整型,以回车结束
int num = scanner.nextInt();
if (num % 2 == 0) {
System.out.println(num + "是偶数");
} else {
System.out.println(num + "是奇数");
}
} else {
System.out.println("输入的不是数字");
}
}
}
标签:数字,System,奇偶性,num,scanner,Scanner,输入,out
From: https://www.cnblogs.com/faith007/p/17211716.html