whileループ、Javaの内部の日付を更新します

Snibb:

イムは、whileループ内のユーザ入力日付と現実世界の日付を比較しようとしています。実行初期は正しいですが、二度目は、その同じ日の滞在を実行します。アイブ氏は、whileループ内の日付を求めてみました、今最も最近にクラスメソッド内からまだ日は同じままです。

どのように私は日付日までを取得することができますか?

import java.util.Date;

import java.util.Scanner;

class Watch {
    Date CurrentTimeAndDate = new Date();

    int CurrentMinutes() {
        int currentMinutes = CurrentTimeAndDate.getMinutes();
        System.out.println(currentMinutes);
        return currentMinutes;
    }
}

public class App {

    public static void main(String[] args) throws InterruptedException {

        Scanner input = new Scanner(System.in);
        String timer = null;
        int i = 0;
        int num = 0;
        Date TimeAndDate = new Date();
        int getDay = TimeAndDate.getDay();
        int getMonth = TimeAndDate.getMonth() + 1;
        int getYear = TimeAndDate.getYear() + 1900;
        int getMinutes = TimeAndDate.getMinutes();
        Watch watch1 = new Watch();

        String[] Month = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
        String[] Day = { "", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
        System.out.println("Current time and date is    " + TimeAndDate);
        System.out.println("Printing my way! " + Day[getDay] + " " + Month[getMonth] + " " + getYear + " " + getMinutes);
        System.out.println(" Enter a short description of what you want reminding about ");
        String rem = input.nextLine();
        System.out.println(" Enter date of reminder 1-7");
        while (i < 7) {
            System.out.println(i + 1 + " = " + Day[i + 1]);
            i++;
        }
        int day = input.nextInt();

        System.out.println("Enter Month of reminder");
        i = 0;
        while (i < 12) {
            System.out.println(i + 1 + " " + "=" + " " + Month[i + 1]);
            i++;
        }
        int month = input.nextInt();
        System.out.println("Enter year");
        int year = input.nextInt();
        System.out.println("Enter Minutes, for testing purposes");
        int userInputMinutes = input.nextInt();
        System.out.println("Date set to remind you about " + rem + " " + Day[day] + " " + Month[month] + " " + year);
        if (year > getYear) {
            System.out.println("Its time to remind you about ");
        } else {
            System.out.println("Waiting");
        }
        int Mins = 0;
        while (userInputMinutes != Mins) {
            Mins = watch1.CurrentMinutes();
            System.out.println("Current Minutes = " + getMinutes);
            System.out.println("Entered minutes =" + userInputMinutes);
            Thread.sleep(10000);
        }
        System.out.println("Its time to remind you about " + rem);
    }
    public static void Date(String time) {
    }

}
Thanga:

あなたは一度だけ新しい日付()を設定しています。あなたはループの反復しながら、その同じでを取得されますので。すべての反復のための新しい日付を取得するには、whileループ内で以下のコードを設定する必要があります

TimeAndDate = new Date();
int getDay = TimeAndDate.getDay();
int getMonth = TimeAndDate.getMonth() + 1;
int getYear = TimeAndDate.getYear() + 1900;
int getMinutes = TimeAndDate.getMinutes();
Watch watch1 = new Watch();

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=374878&siteId=1