Java program to take birth year and tells age
Following program shows you how to take birth year and tells age.
In this program we get birth year from user and tells their age using Year.now().getValue() - birthYear
import java.time.Year;
import java.util.Scanner;
public class Basic8 {
public static void main(String[] args) {
System.out.println("Please enter your date of birth:");
Scanner in = new Scanner(System.in);
int birthYear = in.nextInt();
int age = Year.now().getValue() - birthYear;
System.out.println("Your age is " + age);
}
}
Output:
Please enter your date of birth:
1990
Your age is 28