javaweb 通过用户输入出生年月日/或者姓名,来判断用户的星座,给出一个结论 用idea完成完整代码
时间: 2023-05-23 16:07:26 浏览: 195
```java
import java.util.Scanner;
public class StarSignDetector {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入您的生日(例如:1995-06-10):");
String birthday = scanner.nextLine();
String[] dateTokens = birthday.split("-");
int year = Integer.parseInt(dateTokens[0]);
int month = Integer.parseInt(dateTokens[1]);
int day = Integer.parseInt(dateTokens[2]);
String starSign = "";
if (month == 1 && day >= 20 || month == 2 && day <= 18) {
starSign = "水瓶座";
} else if (month == 2 && day >= 19 || month == 3 && day <= 20) {
starSign = "双鱼座";
} else if (month == 3 && day >= 21 || month == 4 && day <= 19) {
starSign = "白羊座";
} else if (month == 4 && day >= 20 || month == 5 && day <= 20) {
starSign = "金牛座";
} else if (month == 5 && day >= 21 || month == 6 && day <= 21) {
starSign = "双子座";
} else if (month == 6 && day >= 22 || month == 7 && day <= 22) {
starSign = "巨蟹座";
} else if (month == 7 && day >= 23 || month == 8 && day <= 22) {
starSign = "狮子座";
} else if (month == 8 && day >= 23 || month == 9 && day <= 22) {
starSign = "处女座";
} else if (month == 9 && day >= 23 || month == 10 && day <= 22) {
starSign = "天秤座";
} else if (month == 10 && day >= 23 || month == 11 && day <= 21) {
starSign = "天蝎座";
} else if (month == 11 && day >= 22 || month == 12 && day <= 21) {
starSign = "射手座";
} else if (month == 12 && day >= 22 || month == 1 && day <= 19) {
starSign = "摩羯座";
}
System.out.println("您的星座是:" + starSign);
}
}
```
阅读全文