Skip to content

Latest commit

 

History

History
42 lines (29 loc) · 702 Bytes

Ex_1_2_11.md

File metadata and controls

42 lines (29 loc) · 702 Bytes
title date draft tags categories
算法4 Java解答 1.2.11
2019-02-22 07:35:22 +0800
false
JAVA
技术
归档

1.2.11

问题:

Develop an implementation SmartDate of our Date API that raises an exception if the date is not legal.

分析:

主要是判断月份和月份中有多少天

    private static int[] bigmonths = {1, 3, 5, 7, 8, 10, 12};
    private static int[] smallmonth = {4, 6, 9, 11};

    static {
      for (int i = 0; i < bigmonths.length; i++) {
        months[bigmonths[i]] = 31;
      }
      for (int i = 0; i < smallmonth.length; i++) {
        months[smallmonth[i]] = 30;
      }
      months[2] = 28;
    }

参考: