Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Thursday 6 July 2023

How to make Age calculator program in java

 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.


Share:

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate