从键盘任意输入一个整数,编程判断它的奇偶性。

KiKi想知道一个整数的奇偶性,请帮他判断。从键盘任意输入一个整数,编程判断它的奇偶性。
题目描述
KiKi想知道一个整数的奇偶性,请帮他判断。从键盘任意输入一个整数,编程判断它的奇偶性。
输入描述:
多组输入,每行输入包括一个整数。
输出描述:
针对每行输入,输出该数是奇数(Odd)还是偶数(Even)。
第一次代码

public class Main
{
    public static void main(String[] args)
    {
        java.util.Scanner sc = new java.util.Scanner(System.in);
        while(sc.hasNext()){
            int i = sc.nextInt();
            if(i%2==0){
                System.out.println("Even");
            }
            else{
                System.out.println("Odd");
            }
        }sc.close();
    }
}

决定用以下Boolean的运算
代码如下

public class Main
{
    public static void main(String[] args)
    {
        java.util.Scanner sc = new java.util.Scanner(System.in);
        while(sc.hasNext()){
            int i = sc.nextInt();
            System.out.println((i%2==0)?"Even":"Odd");
        }sc.close();
    }
}

你可能感兴趣的:(#,Java程序设计,程序设计)