需求

1.让用户选择它的公历生日

2.计算用户的星座

白羊座: 3月21日~4月19日 (Aries)

金牛座: 4月20日~5月20日 (Taurus)

双子座: 5月21日~6月21日 (Gemini)

巨蟹座: 6月22日~7月22日 (Cancer)

狮子座: 7月23日~8月22日 (Leo)

处女座: 8月23日~9月22日 (Virgo)

天秤座: 9月23日~10月23日 (Libra)

天蝎座: 10月24日~11月21日 (Scorpio)

射手座: 11月22日~12月21日 (Sagittarius)

摩羯座: 12月22日~1月19日 (Capricorn)

水瓶座: 1月20日~2月18日 (Aquarius)

双鱼座: 2月19日~3月20日 (Pisces)

1.让用户选择一个日期

2.计算一个日期是不是在3月21——4月19日之间输出“白羊座”

else if(4.20-520之间)

……

package part2;

import com.yzk18.GUI.GUI;

import java.time.LocalDate;

public class 计算星座 {
    public static void main(String[] args) {
        LocalDate birthDay=GUI.dateBox("请输入生日");
        //System.out.println(birthDay.getMonthValue());
        int month=birthDay.getMonthValue();
        int day=birthDay.getDayOfMonth();
        if (month==3)
        {
            if (day<=20)
            {
                System.out.println("双鱼座");
            }
            else
            {
                System.out.println("白羊座");
            }
        }
        else if (month==4)
            if (day<=19)
            {
                System.out.println("白羊座");
            }
            else
            {
                System.out.println("金牛座");
            }
        else if (month==5)
            if (day<=20)
            {
                System.out.println("金牛座");
            }
            else
            {
                System.out.println("双子座");
            }
        else if (month==6)
            if (day<=21)
            {
                System.out.println("双子座");
            }
            else
            {
                System.out.println("巨蟹座");
            }
        else if (month==7)
            if (day<=22)
            {
                System.out.println("巨蟹座");
            }
            else
            {
                System.out.println("狮子座");
            }
        else if (month==8)
            if (day<=22)
            {
                System.out.println("狮子座");
            }
            else
            {
                System.out.println("处女座");
            }
        else if (month==9)
            if (day<=22)
            {
                System.out.println("处女座");
            }
            else
            {
                System.out.println("天秤座");
            }
        else if (month==10)
            if (day<=23)
            {
                System.out.println("天秤座");
            }
            else
            {
                System.out.println("天蝎座");
            }
        else if (month==11)
            if (day<=21)
            {
                System.out.println("天蝎座");
            }
            else
            {
                System.out.println("射手座");
            }
        else if (month==12)
            if (day<=21)
            {
                System.out.println("射手座");
            }
            else
            {
                System.out.println("摩羯座");
            }
        else if (month==1)
            if (day<=19)
            {
                System.out.println("摩羯座");
            }
            else
            {
                System.out.println("水瓶座");
            }
        else if (month==2)
            if (day<=18)
            {
                System.out.println("水瓶座");
            }
            else
            {
                System.out.println("双鱼座");
            }

    }
}

 

方法2整数的比较

month*100+day=3*100+21=321

4月19=419

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐