项目实战:根据出生日期判断星座
星座 对应的月份范围
水瓶: 0121——0219
双鱼: 0220——0320
白羊: 0321——0420
金牛: 0421——0521
双子: 0522——0621
巨蟹: 0622——0722
狮子: 0723——0823
处女: 0824——0923
天秤: 0924——1023
天蝎: 1024——1122
射手: 1123——1221
摩羯: 1222——0120
代码如下:
import java.util.Scanner;
public class plan03{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Please enter the birthday (1001 is October 1st): ");
int day = sc.nextInt();
int month = day/100;
int date = day%100;
String xz = " ";
switch(month){
case 1:
xz = date< 21 ? "mj" : "sp";
break;
case 2:
xz = date< 20 ? "sp" : "sy";
break;
case 3:
xz = date< 21 ? "sy" : "by";
break;
case 4:
xz = date< 21 ? "by" : "jn";
break;
case 5:
xz = date< 22 ? "jn" : "sz";
break;
case 6:
xz = date< 22 ? "sz" : "jx";
break;
case 7:
xz = date< 23 ? "jx" : "sz";
break;
case 8:
xz = date< 24 ? "sz" : "cn";
break;
case 9:
xz = date< 24 ? "cn" : "tc";
break;
case 10:
xz = date< 24 ? "tc" : "tx";
break;
case 11:
xz = date< 23 ? "mj" : "ss";
break;
case 12:
xz = date< 22 ? "ss" : "mj";
break;
}
System.out.println("Your constellation is "+xz);
}
}