输入一个年份,输出框就能显示这一年是什么生肖

public class test {
    public static void main(String[] args) {
        Animal.zodiac(1910);
    }
}
class Animal{
    public static void zodiac(int num)
    {
    //默认一个年份,从这年开始算起
        int x =1900;
        int tmp=(num-x)%12;
        switch(tmp)
        {
        case 0:
            System.out.println("鼠");
            break;
        case 1:
            System.out.println("牛");
            break;
        case 2:
            System.out.println("虎");
            break;
        case 3:
            System.out.println("兔");
            break;
        case 4:
            System.out.println("龙");
            break;
        case 5:
            System.out.println("蛇");
            break;
        case 6:
            System.out.println("马");
            break;
        case 7:
            System.out.println("羊");
            break;
        case 8:
            System.out.println("猴");
            break;
        case 9:
            System.out.println("鸡");
            break;
        case 10:
            System.out.println("狗");
            break;
        case 11:
            System.out.println("猪");
            break;
        }
    }
}

你可能感兴趣的:(Java)