0

金曜日とその月の13日目の印刷物から、どの日も除外するにはどうすればよいでしょうか。次の行に沿って何かを書き込もうとしています:if(dayofweek!= 5 && dayofmonth!= 13)、次に印刷します。それを次のコードに実装するにはどうすればよいですか?

public class LoopDate {

public static void main(String[] args) {

    //Denotes that Tuesday is the first day of 2013
    int startingDayOfWeek = 2;
    int year = 2013;
    int numDays = 0;
    for (int month = 1; month <= 12; month++) {
        switch (month) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            numDays = 31;
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            numDays = 30;
            break;
        case 2:
            if (((year % 4 == 0) && !(year % 100 == 0))
                    || (year % 400 == 0))
                numDays = 29;
            else
                numDays = 28;
            break;
        default:
            System.out.println("Invalid month.");
            break;
        }
        for (int start = 1; start <= numDays; start++)
            System.out.println(month + "/" + start);


        }
    }
}
4

2 に答える 2

0

試す

    GregorianCalendar c = new GregorianCalendar(2013, 0, 1);
    while (c.get(Calendar.YEAR) == 2013) {
        if (!(c.get(Calendar.DAY_OF_MONTH) == 13 &&  c.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY)) {
            System.out.println(c.getTime());
        }
        c.add(Calendar.DAY_OF_YEAR, 1);
    }
于 2013-02-11T05:09:16.190 に答える
0

joda timeを使用すると、次のようになります。

DateTime today = new DateTime();
if (today.dayOfWeek().getAsText().equals("Friday")) { continue; }
if (today.dayOfMonth().get() == 13) { continue; }
// print here
于 2013-02-11T05:12:42.620 に答える