CodeGym /Java Course /Module 1. Java Syntax /Additional lessons for the level

Additional lessons for the level

Module 1. Java Syntax
Level 20 , Lesson 4
Available

Java switch statement

Imagine that you're a knight stopped at a fork in the road. If you go left, you will lose your horse. If you go right, you will gain knowledge. How would we represent this situation in code? You probably already know that we use constructs like if-then and if-then-else to make these decisions. But what if the road splits not into two, but into ten?

You have roads that are "completely to the right", "slightly to the left of that", "a little bit more to the left" and so on, totaling 10 possible roads? Imagine how your "if-then-else" code will grow in this version! Suppose you have a 10-way fork in the road. For such situations, Java has the switch statement. We'll talk about this fellow several more times.

Enum. Practical examples. Adding constructors and methods

And a few more words about Enum. More precisely, fewer words, but more code and practice. After all, the brains of many people are (quite often) full of mush on this topic rather than knowledge. If you want to get a better feel for the topic, don't be shy: feel free to read and explore as you go.

Comments (1)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Jorge Luis Arteaga Almaraz Level 29, Cochabamba, Bolivia
3 January 2024
I think the question 6 is unclear. While the question talks about HashMap, all the options are written using instances of HashSet :/