import
java.time.Period;
import
java.util.Scanner;
public class
AgeCalculator {
public static void main(String[] args) {
// Create a Scanner object for user
input
Scanner scanner = new
Scanner(System.in);
// Prompt the user for their date of
birth
System.out.print("Enter your birth
year (YYYY): ");
int year = scanner.nextInt();
System.out.print("Enter your birth
month (MM): ");
int month = scanner.nextInt();
System.out.print("Enter your birth
day (DD): ");
int day = scanner.nextInt();
// Close the scanner
scanner.close();
// Get the current date
LocalDate currentDate =
LocalDate.now();
// Create a LocalDate object for the
birth date
LocalDate birthDate =
LocalDate.of(year, month, day);
// Calculate the age using Period
Period age = Period.between(birthDate,
currentDate);
// Display the age
System.out.println("You are "
+ age.getYears() + " years, " + age.getMonths() + " months, and
" + age.getDays() + " days old.");
}
}
