Check Employee Department
This program prints department name based on department code using switch.
Problem Statement
Write a Java program that prints department name for a given department code.
Source Code
| 1 | public class DepartmentSwitch { |
| 2 | public static void main(String[] args) { |
| 3 | int deptCode = 3; |
| 4 | switch(deptCode) { |
| 5 | case 1: System.out.println("HR Department - Eduinq"); break; |
| 6 | case 2: System.out.println("Finance Department - Eduinq"); break; |
| 7 | case 3: System.out.println("IT Department - Eduinq"); break; |
| 8 | case 4: System.out.println("Sales Department - Eduinq"); break; |
| 9 | default: System.out.println("Invalid department - Eduinq"); |
| 10 | } |
| 11 | } |
| 12 | } |
Program Output
IT Department - Eduinq
Explanation
The program uses switch to map department codes to department names. Each case corresponds to a department. If the code matches, the corresponding department name is printed. If no case matches, the default block prints invalid department. This demonstrates how switch can be used to implement code-to-name mapping in organizational contexts. Shows how switch can map codes to department names.