Java Switch Case Practice Sheet
Java Switch Case Practice Sheet
The switch statement is used to choose between multiple options based on the value of a variable.
Syntax:
switch (expression) {
case value1:
// Code to execute
break;
case value2:
// Code to execute
break;
default:
Practice Problems
Basic Level:
Write a program that prints the day name (e.g., Monday, Tuesday) based on number input (1-7).
2. Grade Checker:
A => Excellent
B => Good
C => Average
D => Poor
F => Fail
3. Simple Calculator:
Input two numbers and a character for the operator ('+', '-', '*', '/') and perform the operation.
Java Switch Case Practice Sheet for Beginners
Intermediate Level:
4. Month Days:
Input a number (1-12) and print the number of days in that month (non-leap year).
5. Vowel or Consonant:
Input color name ('red', 'yellow', 'green') and display the action (Stop, Ready, Go).
7. Menu-Driven Calculator:
Display a menu:
1. Add
2. Subtract
3. Multiply
4. Divide
Ask user to choose and input two numbers, perform operation using switch.
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Tips
- switch supports: int, byte, short, char, String (Java 7+), and enums.