7日後の日付を正しく、
出力させる方法を教えて下さい。
間違いとかも指摘して、アドバイス下さい。
当日の日付は表示できます。
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Quiz {
/** 出力する日付の書式 */ private DateFormat df; /** 当日の日付 */ private Calendar today = Calendar.getInstance(); /** * * コンストラクタ */ public Quiz(String format) { this.df = new SimpleDateFormat(format); } /** * 当日の日付を出力。 */ public void printToday() { calendarPrintln(this.today); } /** * カレンダー日付をコンストラクタで指定した書式に合わせて標準出力する。 */ private void calendarPrintln(Calendar cal) { System.out.println(df.format(cal.getTime())); } /** * 7日後の日付を出力。 */ public void printOneWeekLater() { calendarPrint2ln(this.today); } /** * カレンダー日付をコンストラクタで指定した書式に合わせて標準出力する。 * */ private void calendarPrint2ln(Calendar cal) { System.out.println(df.format(cal.getTime())); }
}
public class Quizrun {
public static void main(String[] args) { String format = "yyyy/MM/dd(E)"; Quiz instanceQuiz = new Quiz(format); System.out.println("当日"); instanceQuiz.printToday(); System.out.println("7日後"); instanceQuiz.printOneWeekLater(); }
}
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。