java根據生日判斷生日和星座

來源:互聯網
上載者:User

package com.test;

import java.util.Calendar;

public class Test {

 /**
  * @param args
  */
 
 public static final String[] zodiacArr = { "猴", "雞", "狗", "豬", "鼠", "牛", "虎", "兔", "龍", "蛇", "馬", "羊" };   
   
    public static final String[] constellationArr = { "水瓶座", "雙魚座", "牡羊座", "金牛座", "雙子座", "巨蟹座", "獅子座", "處女座", "天秤座",   
            "天蠍座", "射手座", "魔羯座" };   
      
    public static final int[] constellationEdgeDay = { 20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22 };   
      
    /**  
     * 根據日期擷取生肖  
     * @return  
     */  
    public static String date2Zodica(Calendar time) {   
        return zodiacArr[time.get(Calendar.YEAR) % 12];   
    }   
      
    /**  
     * 根據日期擷取星座  
     * @param time  
     * @return  
     */  
    public static String date2Constellation(Calendar time) {   
        int month = time.get(Calendar.MONTH);   
        int day = time.get(Calendar.DAY_OF_MONTH);   
        if (day < constellationEdgeDay[month]) {   
            month = month - 1;   
        }   
        if (month >= 0) {   
            return constellationArr[month];   
        }   
        //default to return 魔羯   
        return constellationArr[11];   
    }  
 
 public static void main(String[] args) {
  String test = date2Constellation(Calendar.getInstance());
  System.out.println("星座:"+test);
  String test1 = date2Zodica(Calendar.getInstance());
  System.out.println("生肖:"+test1);
 }

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.