日期:2014-05-20 浏览次数:20793 次
public class Test{ public static void main(String[] args) { System.out.println(getDate()); } static String getDate(){ String[] dates = new String[]{"3-4","3-5","3-8","6-4","6-7","9-1","9-5","12-1","12-2","12-8"}; //排除从日期可以确定月份的生日 String[] datesTemp = dates.clone(); int count = 0; for(int i = 0;i < datesTemp.length;i++){ count = 0; String day = datesTemp[i].split("-")[1]; for(int j = 0;j < dates.length;j++){ if(datesTemp[j].split("-")[1].equals(day)){ count++; } } if(count == 1){ String mouth = datesTemp[i].split("-")[0]; for(int j = 0;j < dates.length;j++){ if(datesTemp[j].split("-")[0].equals(mouth)){ dates[j] = ""; } } } } //获取重复的日子 String day = ""; for(int i = 0;i < dates.length;i++){ count = 0; for(int j = i + 1;j < dates.length;j++){ if(!dates[j].equals("") && dates[i].split("-")[1].equals(dates[j].split("-")[1])){ count++; } } if(count != 0){ day = dates[i].split("-")[1]; break; } } //确定只有2个生日的月份 String mouth = ""; for(int i = 0;i < dates.length;i++){ count = 0; for(int j = 0;j < dates.length;j++){ mouth = dates[i].split("-")[0]; if(!dates[j].equals("") && mouth.equals(dates[j].split("-")[0])){ count++; } } if(count != 2){ for(int j = 0;j < dates.length;j++){ if(mouth.equals(dates[j].split("-")[0])){ dates[j] = ""; } } } } //由于小强知道了,那么就不是重复的日子 for(int i = 0;i < dates.length;i++){ if(!dates[i].equals("") && day.equals(dates[i].split("-")[1])){ dates[i] = ""; } } for(int i = 0;i < dates.length;i++){ if(!dates[i].equals("")) return dates[i]; } return null; } }