0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Java switch文

Posted at

if-else if-else が何重にもなる場合switch文ですっきりさせることができる!

☆switch文に書き換えルことができる条件☆
①すべての条件が == で左辺と右辺が一致するかを比較する式(それ以外の >, <, =! でない)
②比較する対象が整数(byte型,short型,int型)、文字列(String型)または文字(char型)の時(小数や真偽値ではない)

☆基本構文☆
switch (条件値) {
case 値① -> {
処理①
}
case 値② -> {
処理②
}
  ・
  ・
  ・
default -> {
処理X

☆ default -> {処理内容}は条件に合致したいときの処理のため不要な場合は省略できる
☆caseの値が複数の場合 ,を使用
  例) case 1,2 -> (1または2)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?