Java Program for Age Calculator
Here we are going to learn most important program of java which is Age Calculator by this java example we will able to calculate age of users. So let's start making code for java age calculator.
import java.time.LocalDate;
import java.time.Period;
import java.util.Scanner;
public class AgeCalculator
{
public static void main(String args[])
{
LocalDate birthDate, currentDate;
Scanner scanner = new Scanner(Sytem.in);
System.out.print("Please Enter your birth date (yyy-mmm-ddd): " );
String birthDateSt = scanner.nextLine();
birthDate = LocalDate.parse(birthDateSt);
currentDate = LocalDate.now();
Period age = Period.between(birthDate, currentDate);
System.out.println("Your age is : "+age.getYears()+" years, "+age.getMonths+" month, and "+age.getDays+" days. ");
scanner.close();
}
}
By using above age calculator program we can easily calculate age.