java根据生日判断生日和星座
2010-08-03 10:48
453 查看
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);
}
}
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);
}
}
相关文章推荐
- 根据生日判断星座
- 【Java】实现一个根据日期判断星座程序的编写
- 【Java】实现一个根据日期判断星座程序的编写
- Java根据生日得出是十二星座的哪一个星座
- PHP 根据身份证号码,获取性别、获取生日、计算年龄、获取地址、获取生肖、获取星座、以及判断是否是身份证号
- 根据身份证判断性别和生日
- 根据身份证号码判断性别 java
- php根据日期判断星座的函数分享
- 根据生日计算星座(Objective-C)
- JAVA判断中英文,并根据中英文自动截取字符串
- (java)根据文件修改时间,判断是否为当天文件,如果不是则删除文件夹内文件
- Java Android 根据银行卡号判断银行名称
- java-根据生日计算周岁
- Java根据文件内容判断是否是图片
- iOS中根据生日计算星座♈️
- 根据生日的月份和日期,一行代码计算星座的js小函数(转)
- java根据用户生日计算年龄
- SVM分类算法,libsvm的Java语言实现-根据语料和测试语料判断准确率的
- java float double string转换和根据是否是小数判断显示格式
- php根据日期判断星座的函数分享