Q:

if-else-else if

I am a beginner in java and i am doing some practiceit questions to brush up on my java skills.
Write a method named season that takes two integers as parameters representing a month and day and that returns a String indicating the season for that month and day. Assume that months are specified as an integer between 1 and 12 (1 for January, 2 for February, and so on) and that the day of the month is a number between 1 and 31.
If the date falls between 12/16 and 3/15, you should return "Winter". If the date falls between 3/16 and 6/15, you should return "Spring". If the date falls between 6/16 and 9/15, you should return "Summer". And if the date falls between 9/16 and 12/15, you should return "Fall".
public static String season(int month,int day){
   
    if(month>=9 && month<=12 && day==15||day==16){
        return "Fall";
    }
    else if (month>=4 && month<=6 && day==16||day==15){
       return "Spring";
     }
    else if (month>=6 && month<=9 && day==16||day==15){
         return "Summer";
     }
     else {
          return"Winter";

         
      }

  
}

But i'm not getting the output.But it seems right to me.Anyone can tell me where did i go wrong?

A:

|| has lower precendence than && and your conditions don't look correct - you probably wanted to write something like:
if((month == 9 && day >= 16) //September, on or after the 16th
      || month == 10         //or October
      || month == 11         //or November
      || (month == 12 && day <=15)) { //or December, but before or on the 15th
    return "Fall";
}

(same comment for the other conditions)

You could make it shorter by using a little hack, but readability is maybe not as good (debatable):
int mdd = month * 100 + day; //date in MDD format, for example 507 for May 7th

if (mdd >= 916 && mdd <= 1215) {
    return "Fall";
}

A:

You should try to write something like this:
if((month>9 && month<12) || (month==9 && day>=16) || (month==12 && day<=15)){
    return "Fall";
} else if 
    ...
}

The precedences are important, also, but you have to think over what you really want to achieve, and build your expression according to that.

