始める無料で始める

Performing date calculation

Date arithmetic allows you to modify dates dynamically. In this exercise, you will calculate both a future date by adding days and a past date by subtracting days from the current date.

この演習はコースの一部です

Input/Output and Streams in Java

コースを見る

演習の手順

  • Get the current date.
  • Add 10 days to the current date.
  • Call method to subtract days from the current date.
  • Provide the correct input to subtract 5 days

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

public class DateArithmetic {
    public static void main(String[] args) {
    	// Get current date
        LocalDate today = ____.____(); 
        
        // Add 10 days
        LocalDate futureDate = today.____(10);
        
        // Subtract 5 days
        LocalDate pastDate = today.____(____); 
        
        System.out.println(futureDate); 
        System.out.println(pastDate);
    }
}
コードを編集して実行