I'm trying to print a String which was initialized within the if-else statement. But I'm having an error regarding dateStr may not have been initialized in the last line. Any suggestion? This is the code:
int currentDay = LocalDateTime.now().getDayOfMonth();
int currentMonth = LocalDateTime.now().getMonthValue();
int currentYear = LocalDateTime.now().getYear();
String dateStr;
if (currentDay < 10 && currentMonth < 10){
dateStr = "0" + currentDay + "/0" + currentMonth + "/" + currentYear;
} else if (currentDay < 10 && currentMonth >= 10) {
dateStr = "0" + currentDay + "/" + currentMonth + "/" + currentYear;
} else if (currentDay >= 10 && currentMonth >= 10){
dateStr = currentDay + "/" + currentMonth + "/" + currentYear;
}
System.out.println(dateStr);