Computer Science, asked by kv6474190, 8 months ago

Write a program to calculate the age of a person in Java​ ( please do it fast..!!)

Attachments:

Answers

Answered by abhayranjan199
0

Answer:

ryt

Explanation:

Method 1:

Direct age calculation:

Using the package java.time.LocalDate the age is calculated when the dob is known. using LocalDate.now() the current date is obtained. using the method between() in java.time.Period the current date and dob are compared. The final age can be obtained using diff.getyears(), diff.getMonths() and diff.getDays() methods.

Syntax:

Period diff=Period.between(l, now);

Method 2:

Using the Calendar object:

Using Calendar object we can also calculate age when dob is in String format. Convert the String to Date object and use getInstance() and setTime() methods to assign a date to calendar objects. using the below code the year, month and date are obtained separately.

Similar questions