java代码如何根据月份日期计算出星座信息呢?
下文笔者讲述使用java代码计算出其星座的方法分享,如下所示
实现思路: 1.获取出生日期的月份和日期信息 2.使用if语句进行判断,检测出其所在的星座信息例:使用月份和日期信息获取星座信息
import java.util.Scanner; public class TestConstellation { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("请输入出生月份:"); int month = scanner.nextInt(); System.out.print("请输入出生日期:"); int day = scanner.nextInt(); if ((month == 1 && day >= 20) || (month == 2 && day <= 18)) { System.out.println("生日" + month + "月" + day + "日是水瓶座"); } else if ((month == 2 && day >= 19) || (month == 3 && day <= 20)) { System.out.println("生日" + month + "月" + day + "日是双鱼座"); } else if ((month == 3 && day >= 21) || (month == 4 && day <= 19)) { System.out.println("生日" + month + "月" + day + "日是白羊座"); } else if ((month == 4 && day >= 20) || (month == 5 && day <= 20)) { System.out.println("生日" + month + "月" + day + "日是金牛座"); } else if ((month == 5 && day >= 21) || (month == 6 && day <= 21)) { System.out.println("生日" + month + "月" + day + "日是双子座"); } else if ((month == 6 && day >= 22) || (month == 7 && day <= 22)) { System.out.println("生日" + month + "月" + day + "日是巨蟹座"); } else if ((month == 7 && day >= 23) || (month == 8 && day <= 22)) { System.out.println("生日" + month + "月" + day + "日是狮子座"); } else if ((month == 8 && day >= 23) || (month == 9 && day <= 22)) { System.out.println("生日" + month + "月" + day + "日是处女座"); } else if ((month == 9 && day >= 23) || (month == 10 && day <= 23)) { System.out.println("生日" + month + "月" + day + "日是天平座"); } else if ((month == 10 && day >= 24) || (month == 11 && day <= 22)) { System.out.println("生日" + month + "月" + day + "日是天蝎座"); } else if ((month == 11 && day >= 23) || (month == 12 && day <= 21)) { System.out.println("生日" + month + "月" + day + "日是射手座"); } else if ((month == 12 && day >= 22) || (month == 1 && day <= 19)) { System.out.println("生日" + month + "月" + day + "日是摩羯座"); } scanner.close(); } }
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。