bluej Programs
6.Write a program to enter the year of birth of a person.Calculate his/her age.
import java.util.*;
class age
{
void main()
{
Scanner sc=new Scanner(System.in);
int d,a,c;
System.out.println("Enter the year of birth of a person:");
d=sc.nextInt();
System.out.println("Enter the current year:");
c=sc.nextInt();
a=c-d;
System.out.println("Age of the Person:"+a);
}
}
Output:
Enter the year of birth of a person: 2013 Enter the current year: 2026 Age of the Person:13
ADVERTISEMENT
