Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Java age from date of birth
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.time.*;
import java.util.*;

public class Exercise32 {
public static void main(String[] args)
{
// date of birth
LocalDate pdate = LocalDate.of(1989, 04, 11);
// current date
LocalDate now = LocalDate.now();
// difference between current date and date of birth
Period diff = Period.between(pdate, now);

System.out.printf("\nI am %d years, %d months and %d days old.\n\n",
diff.getYears(), diff.getMonths(), diff.getDays());
}
}