首页 > 代码库 > Java-判断输入数字的奇偶性

Java-判断输入数字的奇偶性


 1 import java.io.InputStream;
 2 import java.util.Scanner;
 3 
 4 public class ParityCheck {
 5     public static void main(String[] args) {
 6         boolean boo=true;
 7         while(boo){
 8             System.out.println("enter a number");
 9             try {//排除用户输入字符
10                 Scanner input=new Scanner(System.in);//接受用户输入的字符
11                 int number=input.nextInt();
12                 if(number%2==0){//判断奇偶性
13                     System.out.println("it is an even number");
14                 }
15                 else
16                 {
17                     System.out.println("it is odd");
18                 }
19             } catch (Exception e) {
20                 System.out.println("please enter a correct number instead of a character");
21                 continue;
22             }
23             boo=false;
24         }
25     }
26 }

 

 

 

Java-判断输入数字的奇偶性