LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Input/Output and Streams in Java

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

import java.time.LocalDate;

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);
    }
}
Code bearbeiten und ausführen