Topics Index

Print Season depending upon the month

If you need explanation Read this topic

If you need Answer Take test on this topic

Write a program to print the season (Spring, Summer, Monsoon, Winter) depending upon the month number using switch condition.
Note: If the month is 1 to 3 it is Spring season, if the month is 4 to 6 it is Summer, if the month is 7 to 9 it is Monsoon season, if the month is 10 to 12 it is Winter season.
Use System.out.println or System.out.print for printing.

Input (Integer) Printed Output
2 Spring
4 Summer
9 Monsoon
11 Winter

class PrintSeason
    public static void main(String s[])


    public static void printSeason(int monthNumber)

Topic: Using Break In for Loop To Exit

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

for printimg season according to month...... we can do it in a simple way by using if else.... if intmonth is btween 1 to 3 den print spring else if it is between 3-6 print summer else if(monthnumber >6&&monthnum<10) DEN PRINT MONSOON ELSE PRINT WINTER

Posted by Asma Mujtaba Khan    2014-12-16 07:27:07

we can easily implement this program using switch condition.for case 1 and 2 dont give any case 3 give print statement to print spring and give break condition.When a break statement is reached, the switch terminates, and the flow of control jumps to the next line following the switch statement.Not every case needs to contain a break. If no break appears, the flow of control will fall through  to subsequent cases until a break is reached.similarly 4,5 case dont giv any statement,also dont give break statement ,in case 6 give print statement summer and giv break to terminate swich .similarly use the above procedure for monsoon and winter .

Posted by Maheshwari Natarajan    2014-12-16 08:00:25

we can solve this in 2 ways...
Case 1: switch
here write switch case 1 and case 2 empty with out break and in case 3 print the Spring and put case 4 and case 5 empty no break in case 6 print summer and put break case 7 and case 8 empty ad case 9 print mansoon and break...write default print default in it..

Case 2: using nested if-else
if the month in between 1 and 3 than print Spring else if the month in between 4-6 than print summer else if the month between 7-9 than print mansoon else print winter

Posted by Uday Kumar    2014-12-16 09:58:27

This dose is now closed and the winners are Maheshwari Natarajan,  for 'First Correct Comment', Uday Kumar,  for 'Second Correct Comment'. The 'lucky liker' is Uday Kumar. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2014-12-17 07:08:11

© meritcampus 2019

All Rights Reserved.

Open In App