private static boolean getConstantHoliday(final Date date){

int monthDay = Integer.parseInt(DateUtil.getMonth(date)+""+DateUtil.getDay(date));

switch(monthDay){
case 11 :
return true;
case 51:
return true;
case 101:
return true;
case 102:
return true;
case 103:
return true;
case 104:
return true;
case 105:
return true;
default:
return false;
}

}    以上代码是我写的一个小方法,但是总是感觉代码写的不简洁,不知道个位大侠有没有谁能帮我简化一下,谢谢,分数是不会少了。

解决方案 »

  1.   

    把case数值放数组里,再做循环判断
      

  2.   


    switch(monthDay){
    case 11 :
    case 51:
    case 101:
    case 102:
    case 103:
    case 104:
    case 105:
    return true;
    default:
    return false;
    }
      

  3.   

    private static boolean getConstantHoliday(final Date date){

    int monthDay = Integer.parseInt(DateUtil.getMonth(date)+""+DateUtil.getDay(date));

    return 11 == monthDay || 51 == monthDay || 101 == monthDay ||102 == monthDay
       || 103 == monthDay || 104 == monthDay || 105 == monthDay;
    }这是我自己改的,不知道有没有更好的。
      

  4.   

    int[] a = {11,51,101,102,103,104,105};
    for (int i = 0; i < a.length; i++) {
    if (a[i] == monthDay) {
    return true;
    }
    }
    return false;