不说其他,直接贴代码
private final static int[] dayArr = new int[] { 20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22 };
private final static String[] constellationAr = new String[] { "摩羯座", "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "摩羯座" };
public static String getConstellation(int month, int day) {
return day < dayArr[month - 1] ? constellationAr[month - 1] : constellationAr[month];
}
//获取星座
getConstellation(month, day);//month和day都是int类型,需要从日期从获取转换一下类型