Java属相与星座

根据年份输出当年的属相,输入月份和日期,据此判断出是那个星座的。

例如:

你的出生年份:2018
你的出生月份:2
你的出生日子:19
狗双鱼座

  import java.util.Scanner;
    
    public class Test {
      public void constellatory(int month, int day) {
        String constellation = "";
        if (month == 1 && day >= 20 || month == 2 && day <= 18) {
          constellation = "水瓶座";
        }
        if (month == 2 && day >= 19 || month == 3 && day <= 20) {
          constellation = "双鱼座";
        }
        if (month == 3 && day >= 21 || month == 4 && day <= 19) {
          constellation = "白羊座";
        }
        if (month == 4 && day >= 20 || month == 5 && day <= 20) {
          constellation = "金牛座";
        }
        if (month == 5 && day >= 21 || month == 6 && day <= 21) {
          constellation = "双子座";
        }
        if (month == 6 && day >= 22 || month == 7 && day <= 22) {
          constellation = "巨蟹座";
        }
        if (month == 7 && day >= 23 || month == 8 && day <= 22) {
          constellation = "狮子座";
        }
        if (month == 8 && day >= 23 || month == 9 && day <= 22) {
          constellation = "处女座";
        }
        if (month == 9 && day >= 23 || month == 10 && day <= 23) {
          constellation = "天秤座";
        }
        if (month == 10 && day >= 24 || month == 11 && day <= 22) {
          constellation = "天蝎座";
        }
        if (month == 11 && day >= 23 || month == 12 && day <= 21) {
          constellation = "射手座";
        }
        if (month == 12 && day >= 22 || month == 1 && day <= 19) {
          constellation = "摩羯座";
        }
        System.out.println(constellation);
      }
    
    
    
      public void animal(int year) {
        int t = year % 12;
        switch (t) {
          case 0:
            System.out.print("猴"); break;
          case 1:
            System.out.print("鸡"); break;
          case 2:
            System.out.print("狗"); break;
          case 3:
            System.out.print("猪"); break;
          case 4:
            System.out.print("鼠"); break;
          case 5:
            System.out.print("牛"); break;
          case 6:
            System.out.print("虎"); break;
          case 7:
            System.out.print("兔"); break;
          case 8:
            System.out.print("龙"); break;
          case 9:
            System.out.print("蛇"); break;
          case 10:
            System.out.print("马"); break;
          case 11:
            System.out.print("羊"); break;
        }
      }
      public static void main(String[] aegs) {
        Test a = new Test();
        Scanner in=new Scanner(System.in);
        System.out.println("请输入年份:");
        int year=in.nextInt();
        System.out.println("请输入月份:");
        int month=in.nextInt();
        System.out.println("请输入日期:");
        int day=in.nextInt();
        a.animal(year);
        a.constellatory(month,day);
      }
    
    }

欢迎关注

掘金:https://juejin.cn/user/4156573190724030
Github:https://github.com/zhubingran
CSDN:https://blog.csdn.net/qq_43118757
QQ:1330022055

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值