Algorithm
-
Input Birthday:
- Prompt the user to enter the birthdate.
-
Parse Input:
- Parse the entered input to extract day, month, and year components.
-
Get Current Date:
- Obtain the current date.
-
Compare Dates:
- Compare the extracted birthdate with the current date.
-
Check if it's the Birthday:
- If the day and month of the entered date match the current day and month, print "Happy Birthday."
-
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
Todays Date: 2020-07-28
HAPPY BIRTHDAY TO YOU !!
HAPPY BIRTHDAY TO YOU !!
Demonstration
Java Programing Example to Check the birthday and print Happy Birthday message-DevsEnv