2

このサイトでの最初の質問ですが、このサイトは本当に便利だといつも思っています。
私の質問の意味は次のとおりです。

  1. その人に日付を尋ねます (例: 日付を入力 [dd-mm-yyyy]: 16-10-2013)
  2. 2 年間の間隔を尋ねる必要があります (例: 間隔 [yyyy-yyyy]:1800-2000 を指定)

プログラムが実行されると、指定された日付が何曜日であるかを表示する必要があります。この場合は水曜日でした。プログラムがどの年にあるかを調べなければならないよりも、間隔の間に、10 月 16 日の日付も水曜日に落ちました。

したがって、最終的には次のようになります。

Fill in a date: [dd-mm-yyyy]: 16-10-2013
Give an interval [yyyy-yyyy]: 1900-2000
16 October was a wednesday in the following years:
1905 1911 1916 1922 1933 1939 1944 1950 1961 1967 1972 1978 1989 1995 2000

完全な日付は 2013 年 10 月 16 日水曜日です

。小さな (または最大の) 問題は、Java で DATE.function を使用することが許可されていないことです。

誰かが 2 番目の部分で私を助けてくれたら、私は本当に本当に幸せです。なぜなら、私はこれをどのように行うべきかわからないからです

。与えられた日付が何曜日に該当するかを調べるには、Zeller Congruence を使用します


class Day {

Date date; //To grab the month and year form the Date class
           //In this class I check whether the giving date is in the correct form
int day;
int year1; //First interval number
int year2; //Second interval number

final static String[] DAYS_OF_WEEK = {
        "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
        "Friday"
    };

public void dayWeekInterval{
    int interval.year1;
    int interval.year2;

    for(int i = year1; year1 =< year2; year1++) {
        //check if the day of the week in the giving year, is the same as the
        //original year.
    }
}

public void dayOfTheWeek {
    int m = date.getMonth();
    int y = date.getYear();

    if (m &lt; 3) {
        m += 12;
        y -= 1;
    }

    int k = y % 100;
    int j = y / 100;

    int day = ((q + (((m + 1) * 26) / 10) + k + (k / 4) + (j / 4)) +
        (5 * j)) % 7;

    return day;
}

public string ToString(){
    return "" + DAYS_OF_WEEK[day] + day;
}


コードを少し変更しましたが、ネクタイの結び方がわかりません。また、言及するのを忘れていましたが、私はJavaの日付とカレンダー機能を使用することを許可されていません...そして、私は見通しで何か間違ったことをしました..

4

2 に答える 2

0

使えませんDateが使えますCalendarか?次に、これはあなたのコードになります:

    Calendar c = Calendar.getInstance();
    c.set(2013, 9, 16); // month starts at zero
    System.out.printf("Original date is: %tc\n", c);

    int weekday = c.get(Calendar.DAY_OF_WEEK);
    System.out.printf("Weekday of original date is [by number] %d\n", weekday);

    for(int year = 1800; year < 2000; year++) {
        c.set(Calendar.YEAR, year);
        if(weekday == c.get(Calendar.DAY_OF_WEEK))
            System.out.printf("%tc was same weekday!\n", c);
    }
于 2013-10-26T15:42:52.303 に答える