zoukankan      html  css  js  c++  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 }
    
    
    
     
  • 相关阅读:
    Linux
    python 鸢尾花数据集报表展示
    python 词云
    毕业设计回顾
    editor.md
    杂记
    垃圾回收器
    杂记
    随笔
    杂记
  • 原文地址:https://www.cnblogs.com/yigenmao/p/6938077.html
Copyright © 2011-2022 走看看