Algorithm


  1. Input Birthday:

    • Prompt the user to enter the birthdate.
  2. Parse Input:

    • Parse the entered input to extract day, month, and year components.
  3. Get Current Date:

    • Obtain the current date.
  4. Compare Dates:

    • Compare the extracted birthdate with the current date.
  5. Check if it's the Birthday:

    • If the day and month of the entered date match the current day and month, print "Happy Birthday."
  6. Print Message:

    • If it's the birthday, print a "Happy Birthday" message. Otherwise, print a different message.

 

Code Examples

#1 Code Example- Check birthday and return Happy Birthday message

Code - Java Programming

import java.time.LocalDate;
import java.time.Month;

public class Main {
   public static void main(String args[]) {

    // declare variables for birthday
    int birthDate = 23;
    Month birthMonth = Month.SEPTEMBER;

    // get current date
    LocalDate currentDate = LocalDate.now();
    System.out.println("Todays Date: " + currentDate);

    // get current date and month
    int date = currentDate.getDayOfMonth();
    Month month = currentDate.getMonth();

    if(date == birthDate && month == birthMonth) {
      System.out.println("HAPPY BIRTHDAY TO YOU !!");
    }
    else {
      System.out.println("Today is not my birthday.");
    }
   }
}
Copy The Code & Try With Live Editor

Output

x
+
cmd
Todays Date: 2020-07-28
HAPPY BIRTHDAY TO YOU !!
Advertisements

Demonstration


Java Programing Example to Check the birthday and print Happy Birthday message-DevsEnv