Untitled
unknown
plain_text
a month ago
1.2 kB
4
Indexable
import java.util.Scanner;
import java.time.LocalDate;
import java.time.DayOfWeek;
public class DayFinder {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter day: ");
int day = sc.nextInt();
System.out.print("Enter month: ");
int month = sc.nextInt();
System.out.print("Enter year: ");
int year = sc.nextInt();
try {
LocalDate inputDate = LocalDate.of(year, month, day);
LocalDate startDate = LocalDate.of(1990, 3, 1);
LocalDate endDate = LocalDate.of(1991, 2, 28);
if (inputDate.isBefore(startDate) || inputDate.isAfter(endDate)) {
System.out.println("Error: Date is out of valid range!");
System.out.println("Valid range: March 1, 1990 to February 28, 1991");
} else {
DayOfWeek dayOfWeek = inputDate.getDayOfWeek();
System.out.println("Day of the week is: " + dayOfWeek);
}
} catch (Exception e) {
System.out.println("Invalid date entered!");
}
sc.close();
}
}Editor is loading...
Leave a Comment