Add tags

Add tags to the following comment

毎月の 13 日が金曜かどうかを調べ上げています。

初めに現在が 13 日であるかどうか調べ、 ・13日より前なら、現在の日時を 13 日に設定 ・13日より後なら、現在の日時を翌月の 13 日に設定 とし、調べ上げを開始しています。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.*;
import static java.util.Calendar.*;
public class Count13Friday {

    public static void main(String[] args) {
        Calendar to = new GregorianCalendar(2013, 12, 31);
        Calendar current = new GregorianCalendar();

        int currentDate = current.get(DATE);
        if (currentDate != 13) {
            current.set(DATE, 13);
            if (13 < currentDate) {
                current.add(MONTH, 1);
            }
        }

        List<Date> fridays = new ArrayList<Date>();
        while (current.compareTo(to) <= 0) {
            if (current.get(DAY_OF_WEEK) == FRIDAY) {
                fridays.add(current.getTime());
            }
            current.add(MONTH, 1);
        }
        System.out.println("Fridays = " + fridays);
    }

}

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...