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:

3 comments:

  1. That was great article to read.
    Java training in Pune

    ReplyDelete
  2. Very useful and informative content! I really appreciate the way you explained the concepts in a simple and clear manner. For learners who want practical exposure and hands-on experience, the Best Java Real Time Projects Online Training is a great option to build industry-level skills. Thank you for sharing such valuable information!

    ReplyDelete
  3. Very useful and informative content! I really appreciate the way you explained the concepts in a simple and clear manner. For learners who want practical exposure and hands-on experience, the Best Java Real Time Projects Online Training is a great option to build industry-level skills. Thank you for sharing such valuable information!

    ReplyDelete

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate