Respuesta :

Answer:

import java.util.Calendar;

import java.util.Date;

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

       System.out.print("Insert Date of Birth: ");

       String[] dateofbirth = new String[3];

       Scanner s1 = new Scanner(System.in);

       int a=0;

       while (a<=2) {

           dateofbirth[a] = s1.next();

           a++;

       }

       System.out.print("Insert future date: ");

       String[] futuredate = new String[3];

       Scanner t1 = new Scanner(System.in);

       a=0;

       while (a<=2) {

           futuredate[a] = t1.next();

           a++;

       }

       Calendar cal1 = Calendar.getInstance();

       cal1.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateofbirth[0]));

       cal1.set(Calendar.MONTH, Integer.parseInt(dateofbirth[1]));

       cal1.set(Calendar.YEAR, Integer.parseInt(dateofbirth[2]));

       Date first_Date = cal1.getTime();

       cal1.set(Calendar.DAY_OF_MONTH, Integer.parseInt(futuredate[0]));

       cal1.set(Calendar.MONTH, Integer.parseInt(futuredate[1]));

       cal1.set(Calendar.YEAR, Integer.parseInt(futuredate[2]));

       Date second_Date = cal1.getTime();

       long diff = second_Date.getTime() - first_Date.getTime();

       System.out.println ("Age in Days: " + diff / 1000 / 60 / 60 / 24/365);

   }

}

Explanation:

Please check the answer section. In this program we have created two strings, and inpit two dates through them. And then we parse the string items, and store the days, months and years in the calander instance, and we create two such instance. And finally, we find the differene and print the age in days.

ACCESS MORE