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 }
 
 

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM