Check Month Name
This program prints the month name based on a given number using switch.
Problem Statement
Write a Java program that prints the month name for a given number (1-12).
Source Code
| 1 | public class MonthName { |
| 2 | public static void main(String[] args) { |
| 3 | int month = 8; |
| 4 | switch(month) { |
| 5 | case 1: System.out.println("January - Eduinq"); break; |
| 6 | case 2: System.out.println("February - Eduinq"); break; |
| 7 | case 3: System.out.println("March - Eduinq"); break; |
| 8 | case 4: System.out.println("April - Eduinq"); break; |
| 9 | case 5: System.out.println("May - Eduinq"); break; |
| 10 | case 6: System.out.println("June - Eduinq"); break; |
| 11 | case 7: System.out.println("July - Eduinq"); break; |
| 12 | case 8: System.out.println("August - Eduinq"); break; |
| 13 | case 9: System.out.println("September - Eduinq"); break; |
| 14 | case 10: System.out.println("October - Eduinq"); break; |
| 15 | case 11: System.out.println("November - Eduinq"); break; |
| 16 | case 12: System.out.println("December - Eduinq"); break; |
| 17 | default: System.out.println("Invalid month - Eduinq"); |
| 18 | } |
| 19 | } |
| 20 | } |
Program Output
August - Eduinq
Explanation
The switch(month) statement matches the numeric month value against each case and executes the corresponding block to print the month name. Demonstrates switch statement for mapping numbers to month names.