The source code to add days to the current date is given below. The given program is compiled and executed successfully.
// Java program to add days to the
// current date
import java.util.*;
public class Main {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 10);
System.out.println("Date after 10 days: " + cal.getTime());
}
}
Output:
Date after 10 days: Tue Apr 12 05:22:07 GMT 2022
Explanation:
In the above program, we created a class Main that contains a static method main(). The main() method is the entry point for the program, here we created the object of the Calendar class and added the 10 days to the current date using add() method, and printed the result.
Program/Source Code:
The source code to add days to the current date is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a class Main that contains a static method main(). The main() method is the entry point for the program, here we created the object of the Calendar class and added the 10 days to the current date using add() method, and printed the result.