[go: up one dir, main page]

0% found this document useful (0 votes)
5 views2 pages

Java Switch Case Practice Sheet

The document provides an overview of the Java switch statement, including its syntax and usage for selecting between multiple options based on a variable's value. It includes practice problems for beginners and intermediate learners, such as creating a day of the week program, a grade checker, and a simple calculator. Additional tasks involve a menu-driven calculator and a mini ATM simulator, along with tips for effective use of the switch statement.

Uploaded by

rohanbisaria58
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Java Switch Case Practice Sheet

The document provides an overview of the Java switch statement, including its syntax and usage for selecting between multiple options based on a variable's value. It includes practice problems for beginners and intermediate learners, such as creating a day of the week program, a grade checker, and a simple calculator. Additional tasks involve a menu-driven calculator and a mini ATM simulator, along with tips for effective use of the switch statement.

Uploaded by

rohanbisaria58
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Switch Case Practice Sheet for Beginners

What is a switch Statement?

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:

// Code to execute if no case matches

Practice Problems

Basic Level:

1. Day of the Week:

Write a program that prints the day name (e.g., Monday, Tuesday) based on number input (1-7).

2. Grade Checker:

Input a character ('A', 'B', 'C', 'D', 'F') and print:

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 a lowercase alphabet and determine if it is a vowel or consonant using switch.

6. Traffic Light System:

Input color name ('red', 'yellow', 'green') and display the action (Stop, Ready, Go).

Bonus: Small Program Tasks:

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.

8. Mini ATM Simulator:

Create a switch menu:

1. Check Balance

2. Deposit

3. Withdraw

4. Exit

Simulate balance operations.

Tips

- Always include a 'default' case.

- Use 'break' to prevent fall-through.

- switch supports: int, byte, short, char, String (Java 7+), and enums.

You might also like