根据年份输出当年的属相,输入月份和日期,据此判断出是那个星座的。
例如:
你的出生年份: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
优快云:https://blog.youkuaiyun.com/qq_43118757
QQ:1330022055