age calculator computes age in terms of years, months, weeks, days, hours, minutes, and seconds, given a date of birth.
Create java age calculator using javacoe programming
This is program that count value of age between year of birth input year and now year then we got the age actualy.
This is the java code:
import java.util.Scanner;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
public class umur{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("-------Age Calculator------------");
System.out.println("Insert Year of birth? >>>");
int year = sc.nextInt();
System.out.println("insert Month of birth? >>>");
int month = sc.nextInt();
System.out.println("Insert Day of birth? >>>");
int day = sc.nextInt();
LocalDate cur = LocalDate.now();
LocalDate brn = LocalDate.of(year, month, day);
long years = ChronoUnit.YEARS.between(brn, cur);
System.out.printf("User is %d years old", years);
}
}
Tidak ada komentar:
Posting Komentar