Detect months with 31 days

前端 未结 19 1618
南旧
南旧 2020-12-18 01:53

Is there an analogous form of the following code:

if(month == 4,6,9,11)
{
  do something;
}

Or must it be:

if(month == 4 ||         


        
19条回答
  •  一向
    一向 (楼主)
    2020-12-18 02:23

    A rather literal translation into Java would be:

    if (Arrays.binarySearch(new int[] { 4, 6, 9, 11 }, month) >= 0) {
    

    I don't know what is so special about 4, 6, 9 and 11. You are probably better off using an enum, together with EnumSet or perhaps a method on the enum. OTOH, perhaps JodaTime does something useful.

提交回复
热议问题