Enter your birth of Date in this format - dd mm yyyy, please give a space after dd and mm and yyy for organization. Sample Input: "12 09 2000" please include space like this only.

Program:

import java.util.Scanner;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Program
{
    public static void main(String[] args) {
       
    try{
        Scanner in = new Scanner(System.in);
        String input = in.nextLine();
        input = input.trim();
        int count = 0;
        int z = input.indexOf(' ');
        int z1 = input.lastIndexOf(' ');
        String day = input.substring(0,z);
        String month = input.substring((z+1),z1);
        String year = input.substring((z1+1));
        day = day.trim();
//         let heart beat of average human is be 80 beats per minute
        month = month.trim();
        year = year.trim();
        int dd = Integer.parseInt(day);
        int mm = Integer.parseInt(month);
        int yyyy = Integer.parseInt(year);
        int current_age = 2020;
        String mon[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
       
        String m_onth2 = mon[mm-1];
        int hoom = mm - 1;
       
        System.out.println("Your Date of Birth is "+dd+"/"+mm+"/"+yyyy+"\n");
        System.out.println("The month in which you born is "+mon[mm-1]+"\n");
        System.out.println("Your current age "+(2020 - yyyy)+"\n");
        if (yyyy % 4 == 0){
            System.out.println("The year you born is a leap year \n");}
        else{
            System.out.println("The year you born is not a leap year \n");}
          // Date date=java.util.Calendar.getInstance().getTime();
        DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
       Date dateobj = new Date();
       String gTime = df.format(dateobj);
   
       /*getting current date time using calendar class
        * An Alternative of above*/
       Calendar calobj = Calendar.getInstance();
    //   System.out.println(df.format(calobj.getTime()));
    gTime = gTime.trim();
    int slash = gTime.indexOf('/');
    int last_slash = gTime.lastIndexOf('/');
    String left = gTime.substring((slash+1),last_slash);
    int space = gTime.lastIndexOf(' ');
    int no_month = Integer.parseInt(left);
    gTime = gTime.substring(0,space);
        System.out.println("Today Current date is "+gTime+"\n");
        System.out.println("Approx time your heart beats till your birth to now year "+((2020-yyyy)*525600*80)+"\n");
      
        String month2 = mon[no_month-1];
        if (mm == 1){
        System.out.println("6 month left for your birthday \n");}
        else if (mm == 2){
        System.out.println("7 month left for your birthday \n");}
        else if(mm == 3){
        System.out.println("8 month left for your birthday \n");}
       else if(mm == 4){
       System.out.println("9 month left for your birthday \n");}
       else if(mm == 5){
       System.out.println("10 month left for your birthday \n");}
       else if(mm == 6){
       System.out.println("11 month left for your birthday \n");}
       else if(mm == 7){
       System.out.println("12 month left for your birthday \n");}
       else{
       int ij = Math.min(no_month,mm);
       int ji = Math.max(no_month,mm);
       System.out.println((ji-ij)+" month left for your birthday \n");}
       System.out.println("=================================");
        System.out.println("Upvote it ,Have a technical day, By SVRR TECH Team!");}
        catch (Exception e){
            System.out.println("Read the text given after '//' sign for know how it is work and then try");
        }
    }
}

OUTPUT:



Post a Comment

Previous Post Next Post