-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathage.java
More file actions
28 lines (21 loc) · 1.02 KB
/
age.java
File metadata and controls
28 lines (21 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
import java.time.Period;
import java.util.Scanner;
public class AgeCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your date of birth (YYYY-MM-DD): ");
String dobInput = scanner.nextLine();
LocalDate dob = LocalDate.parse(dobInput);
LocalDate currentDate = LocalDate.now();
Period age = Period.between(dob, currentDate);
System.out.println("Your age is: " + age.getYears() + " years, " + age.getMonths() + " months, and " + age.getDays() + " days.");
scanner.close();
}
}