Challenge: Days Until
Completed
Read two dates in the form yyyy-mm-dd (one per line). Print the number of days from the first to the second, and the day of the week of the second date.
Input
Two lines, each a date like 2026-10-18. The second date is not before the first.
Output
Days: <n> That is a <DAY OF WEEK>
Example
Input
2026-10-18 2027-01-01
Output
Days: 75 That is a FRIDAY
Editor
Java
Hints
LocalDate.parse("2026-10-18") understands this format directly.
ChronoUnit.DAYS.between(a, b)
Solution explanation
java.time knows about leap years, so 2024-02-28 to 2024-03-01 is correctly 2 days.
Show solution
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
LocalDate a = LocalDate.parse(sc.nextLine().trim());
LocalDate b = LocalDate.parse(sc.nextLine().trim());
System.out.println("Days: " + ChronoUnit.DAYS.between(a, b));
System.out.println("That is a " + b.getDayOfWeek());
}
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module