Skip to content
Advertisement

Why wrong greeting is coming in Java [closed]

I wanted to make a program that greets you according to the time of day . I live in India so the zoneid that I used was Asia/Kolkata The timezone here is IST(GMT+5:30). And while I am writing this question the time here is 12:49 PM . Still this print the output good night idk what is wrong with the code . THE CODE IS ==

JavaScript

I used LocalDateTime instead of LocalTime because I need to do some more operations also and I think that shouldn’t have affected the output . I think the problem is with the conditions that I gave . Please help me ☆

Advertisement

Answer

If the hour is 12, it is not present in any of the if statements. So the control is going to else. Put >= instead of >. Change

JavaScript

to

JavaScript

similarly for others.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement