এই নিবন্ধে, আমরা বুঝব কিভাবে জন্মদিন চেক করতে হয় এবং শুভ জন্মদিনের বার্তা প্রিন্ট করতে হয়। জন্মদিন পরীক্ষা করা বর্তমান দিন এবং প্রদত্ত জন্মদিনের তুলনা করে সম্পন্ন হয়৷
নীচে একই -
এর একটি প্রদর্শন রয়েছে৷ইনপুট
ধরুন আমাদের ইনপুট হল −
Birthday Date: 15 July
আউটপুট
কাঙ্খিত আউটপুট হবে −
Today’s Date is 20-12-2021 Today is not my birthday
অ্যালগরিদম
Step 1 - START Step 2 - Declare variables for month and dates values namely month_of_birth and date_of_birth Step 3 - Read the required values from the user/ define the values Step 4 - Use LocalDate.now() function to get the current date and store it in the variable. Step 5 – Using an if loop, compare the current month and date value with the input date and month values respectively. If the values match, the result is true. Step 5- Display the result Step 6- Stop
উদাহরণ 1
import java.time.LocalDate;
import java.time.Month;
public class HappyBirthday {
public static void main(String args[]) {
int date_of_birth = 15;
Month month_of_birth = Month.JULY;
System.out.println("The required packages have been imported");
LocalDate current_date = LocalDate.now();
System.out.println("Today's Date is " + current_date);
System.out.println("The birthday is defined as : " +date_of_birth + " " +month_of_birth);
int date = current_date.getDayOfMonth();
Month month = current_date.getMonth();
if(date == date_of_birth && month == month_of_birth) {
System.out.println("HAPPY BIRTHDAY TO YOU !!");
} else {
System.out.println("Your birthday is not today ");
}
}
} আউটপুট
The required packages have been imported Today's Date is 2022-02-09 The birthday is defined as : 15 JULY Your birthday is not today
উদাহরণ 2
এখানে, পূর্ণসংখ্যা পূর্বে সংজ্ঞায়িত করা হয়েছে, এবং এর মান অ্যাক্সেস করা হয়েছে এবং কনসোলে প্রদর্শিত হয়েছে।
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Birthday {
public static void main(String[] args) throws ParseException {
SimpleDateFormat s = new SimpleDateFormat("MM-dd");
Date today = s.parse("10-15");
Date my_birthday_date = s.parse("10-15");
System.out.println("The birthday date is defined as October 15th" );
if (today.compareTo(my_birthday_date) == 0) {
System.out.println("Happy Birthday!!");
} else {
System.out.println("Today is not tour birthday");
}
}
} আউটপুট
The birthday date is defined as October 15th Happy Birthday!!