Java conditional branching: How to create and study switch statements

-Today, I tried to handle conditional branching: switch statement.

A switch statement is the execution of one of many options.

If there are some conditional branches in the "switch statement", you can write more clearly than in the "if statement".

It can also be used to compare whether the right and left sides are equal.

To write a conditional branch, write "switch (variable you want to judge) {case value you want to branch: processing break;}" like this.

Write the variable "group" you want to judge in "()", and then in "{} (block)"

In "case", write the value you want to branch by the variable of "group", close it with ": (colon)", and close it. Write the processing when "group" is "pirate".

Keep in mind that the ": (colon)" after the "case" is not the "; (semicolon)" you always write.

Also, be aware that you often forget to write "break;".


In the case of some conditional branches like this, you can use the "switch statement" to describe it more clearly than the "if statement".

27th, why not ... (laughs)


** Study method ** Watch a programming video that explains carefully. ↓ to imitate.

The video is practical and easy to understand.

Well then, thank you for your hard work today.

Recommended Posts

Java conditional branching: How to create and study switch statements
How to get and study java SE8 Gold
Java if and switch statements
java (conditional branching and repetition)
Basics of Java development ~ How to write a program (flow and conditional branching) ~
[Java] How to create a folder
Java study # 4 (conditional branching / if statement)
Java implementation to create and solve mazes
[Java] How to output and write files!
How to switch Java versions on Mac
[Java ~ Conditional branching / Iterative processing ~] Study memo (3)
How to switch between multiple Java versions
[Introduction to Java] Conditional branching (if statement, if-else statement, else if statement, ternary operator, switch statement)
How to create your own annotation in Java and get the value
[Java] How to use FileReader class and BufferedReader class
[Java] How to get and output standard input
[Java] How to switch from open jdk to oracle jdk
How to access Java Private methods and fields
[Java] How to use Calendar class and Date class
How to create docker-compose
How to create a Java environment in just 3 seconds
[Ruby] How to use standard output in conditional branching
[Java] Types of comments and how to write them
Java memory management and how to read GC Viewer
How to create a data URI (base64) in Java
How to convert A to a and a to A using AND and OR in Java
How to create and execute method, Proc, Method class objects
(Ruby on Rails6) How to create models and tables
Study Java # 2 (\ mark and operator)
How to create an application
How to lower java version
[Java] How to use Map
Ruby study memo (conditional branching)
Java --How to make JTable
How to create a lightweight container image for Java apps
Difference between Java and JavaScript (how to find the average)
How to use java Optional
How to minimize Java images
How to write java comments
What I learned in Java (Part 4) Conditional branching and repetition
How to use java class
[Java] How to use Optional ②
[Java] How to use removeAll ()
[Java] How to display Wingdings
[Java] How to use string.format
What happened in "Java 8 to Java 11" and how to build an environment
How to use Java Map
How to call and use API in Java (Spring Boot)
[Java Silver] Things to be aware of regarding switch statements
How to set Java constants
How to write and notes when migrating from VB to JAVA
How to dynamically switch JDK when building Java in Gradle
How to develop and register a Sota app in Java
How to use Java variables
Differences in how to handle strings between Java and Perl
How to convert Java radix
How to switch Java in the OpenJDK era on Mac
[Java] How to implement multithreading
[Java] How to use Optional ①
How to initialize Java array
Study Java: Use Timer to create something like a bomb timer