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

Sure

Uploaded by

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

Sure

Uploaded by

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

Sure, here are 20 Java exercises that involve the use of the `switch` statement.

These exercises cover


a range of scenarios and difficulty levels to help you practice your switch statement skills.

1. Write a program that takes a day of the week (as a number) and prints the corresponding day
name using a `switch` statement.

2. Create a program that reads a month (as a number) and outputs the number of days in that
month using a `switch` statement.

3. Build a simple calculator program that performs addition, subtraction, multiplication, and division
based on user input with a `switch` statement.

4. Write a program that takes a grade (A, B, C, D, or F) and prints a corresponding message using a
`switch` statement.

5. Create a program that takes an integer and determines whether it's even or odd using a `switch`
statement.

6. Write a program that converts a numeric grade (e.g., 92) to a letter grade (A, B, C, D, F) using a
`switch` statement.

7. Implement a program that takes a season (spring, summer, autumn, or winter) and prints a
message indicating which months are in that season using a `switch` statement.

8. Develop a program that takes a single character and determines if it is a vowel or a consonant
using a `switch` statement.

9. Create a simple menu-driven program that allows the user to select options (e.g., display a
message, quit) using a `switch` statement.

10. Write a program that takes a number from 1 to 12 and displays the corresponding month name
using a `switch` statement.

11. Implement a program that calculates the area or perimeter of a square or rectangle based on
user input using a `switch` statement.

12. Build a program that takes a country code (e.g., USA, UK, France) and prints the corresponding
currency using a `switch` statement.

13. Write a program that determines whether a given year is a leap year or not using a `switch`
statement.
14. Create a program that takes a day, month, and year as input and prints the date in a specific
format (e.g., "MM/DD/YYYY") using a `switch` statement.

15. Build a program that converts between different temperature units (e.g., Celsius to Fahrenheit,
Fahrenheit to Celsius) based on user input with a `switch` statement.

16. Implement a program that simulates a simple traffic light with three states (red, yellow, green)
using a `switch` statement.

17. Write a program that takes a number and determines if it's positive, negative, or zero using a
`switch` statement.

18. Create a program that takes a simple arithmetic expression (e.g., 2 + 3) and evaluates it using a
`switch` statement.

19. Build a program that reads a fruit name and prints its color using a `switch` statement.

20. Implement a program that simulates a basic ATM with options like checking balance, deposit,
and withdraw using a `switch` statement.

You might also like