日常练习代码练习(奇偶数判读系统)

import java.util.Scanner;

public class Parity02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("欢迎来到奇偶数判读系统");
        System.out.println("请输入一个整数:");
        boolean flag;
        while(true){
            flag = true;
            while (flag) {
                flag = false;
                try {
                    Scanner scanner1 = new Scanner(System.in);
                    int number = scanner1.nextInt();
                    System.out.println(number);
                    if(number%2==0){
                        System.out.println("这个个偶数");
                    }else{
                        System.out.println("这是个奇数");
                    }
                } catch (Exception e) {
                    System.out.println("您输入的可不是整数哦");
                    System.out.println("请重新输入一个整数!!!");
                    flag = true;
                }
            }
            while(true){
                System.out.println("是否需要再判断一个数,输入yes/no");
                String judge = scanner.next();
                System.out.println(judge);
                if(judge.equals("yes")){
                    System.out.println("请再输入一个整数");
                    break;
                }else if(judge.equals("no")){
                    System.out.println("欢迎与您的再次相约");
                    return;
                }else
                    System.out.println("您的输入有误,请重新输入");//键盘就算输入正确了
            }
            }
    }
}

你可能感兴趣的:(java)