{"id":183,"date":"2024-01-01T17:05:56","date_gmt":"2024-01-01T08:05:56","guid":{"rendered":"https:\/\/se-pg-toolbox.com\/?p=183"},"modified":"2024-01-01T17:05:56","modified_gmt":"2024-01-01T08:05:56","slug":"%e3%80%90java%e3%80%91switch%e6%96%87%e3%82%92%e4%bd%bf%e3%81%86%e6%99%82%e3%81%afcase%e3%81%ae%e6%9c%80%e5%be%8c%e3%81%abbreak%e3%82%92%e5%bf%85%e3%81%9a%e6%9b%b8%e3%81%8f%e3%81%93%e3%81%a8%e3%80%90","status":"publish","type":"post","link":"https:\/\/se-pg-toolbox.com\/?p=183","title":{"rendered":"\u3010Java\u3011switch\u6587\u3092\u4f7f\u3046\u6642\u306fcase\u306e\u6700\u5f8c\u306bbreak;\u3092\u5fc5\u305a\u66f8\u304f\u3053\u3068\u3010\u57fa\u790e\u7de8\u3011"},"content":{"rendered":"\n<p>if\u6587\u3067\u591a\u304f\u306e\u5206\u5c90\u304c\u767a\u751f\u3057\u3001else if\u3092\u4f55\u5ea6\u3082\u66f8\u304b\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u5834\u5408\u3001switch\u6587\u3092\u4f7f\u3063\u3066\u898b\u3084\u3059\u304f\u66f8\u304f\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br><br>\u3057\u304b\u3057\u3001switch\u6587\u3092\u66f8\u304f\u306b\u3042\u305f\u3063\u3066\u898b\u843d\u3068\u3057\u3084\u3059\u3044\u70b9\u304c\u3042\u308a\u307e\u3059\u3002<br><br>\u305d\u308c\u306fcase\u306e\u6700\u5f8c\u306bbreak;\u3092\u66f8\u304b\u305a\u306b\u4e88\u60f3\u5916\u306e\u52d5\u4f5c\u3092\u3057\u3066\u3057\u307e\u3046\u3053\u3068\u3067\u3059\u3002<br><br>\u4eca\u56de\u306fcase\u306e\u6700\u5f8c\u306bbreak;\u3092\u66f8\u304b\u306a\u3044\u3068\u3069\u3046\u306a\u308b\u306e\u304b\uff1f<br><br>\u52d5\u4f5c\u3092\u898b\u306a\u304c\u3089break;\u304c\u5fc5\u8981\u306a\u7406\u7531\u3092\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">switch\u6587\u306ecase:\u306e\u6700\u5f8c\u306bbreak;\u3092\u66f8\u304b\u306a\u3044\u3068\u3069\u3046\u306a\u308b\u306e\u304b\uff1f<\/h2>\n\n\n\n<p>\u3067\u306f\u3001\u307e\u305a\u3001switch\u6587\u306ecase\u306e\u6700\u5f8c\u306bbreak;\u3092\u66f8\u304b\u306a\u3044\u3068\u3069\u3046\u306a\u308b\u306e\u304b\uff1f<br><br>\u4ee5\u4e0b\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u7528\u3044\u3066\u8aac\u660e\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\t\/\/switch\u5206\u306ecase:\u5185\u306e\u51e6\u7406\u306bbreak;\u3092\u66f8\u304b\u306a\u3044\u5834\u5408\n\tpublic void swNoBreak() {\n\t\tint num1 = 5;\n\t\tint num2 = 2;\n\t\t\n\t\tswitch(num2) {\n\t\t\t\/\/num2\u304c0\u306e\u5834\u5408\u306fnum2\u3092\u666e\u901a\u306b\u52a0\u7b97\n\t\tcase 0:\n\t\t\tnum1 = num1 + num2;\n\t\t\t\/\/num2\u304c1\u306e\u5834\u5408\u306fnum2\u30922\u500d\u3057\u305f\u3082\u306e\u3092\u52a0\u7b97\n\t\tcase 1:\n\t\t\tnum1 = num1 + num2 * 2;\n\t\t\t\/\/num2\u304c2\u306e\u5834\u5408\u306fnum2\u30923\u500d\u3057\u305f\u3082\u306e\u3092\u52a0\u7b97\n\t\tcase 2:\n\t\t\tnum1 = num1 + num2 * 3;\n\t\t\t\/\/num2\u304c3\u306e\u5834\u5408\u306fnum2\u30924\u500d\u3057\u305f\u3082\u306e\u3092\u52a0\u7b97\n\t\tcase 3:\n\t\t\tnum1 = num1 + num2 * 4;\n\t\t\t\/\/num2\u304c4\u306e\u5834\u5408\u306fnum2\u30925\u500d\u3057\u305f\u3082\u306e\u3092\u52a0\u7b97\n\t\tcase 4:\n\t\t\tnum1 = num1 + num2 * 5;\n\t\t\t\/\/num2\u304c5\u306e\u5834\u5408\u306fnum2\u30926\u500d\u3057\u305f\u3082\u306e\u3092\u52a0\u7b97\n\t\tcase 5:\n\t\t\tnum1 = num1 + num2 * 6;\n\t\t\t\/\/num2\u304c1\uff5e5\u306e\u3044\u305a\u308c\u3067\u3082\u306a\u3044\u5834\u5408\u306fnum2\u309210\u500d\u3057\u305f\u3082\u306e\u3092\u52a0\u7b97\n\t\tdefault:\n\t\t\tnum1 = num1 + num2 * 10;\n\t\t}\n\t\t\/\/\u3053\u3053\u3067\u51fa\u529b\u3055\u308c\u308b\u306e\u306f11\uff1f\n\t\tSystem.out.println(num1);\n\t}<\/code><\/pre><\/div>\n\n\n\n<p>\u3053\u306e\u30bd\u30fc\u30b9\u3067\u306fnum2=2\u306a\u306e\u3067\u300114\u884c\u76ee\u306ecase 2:\u306e\u3068\u3053\u308d\u3092\u901a\u308a\u30015+2\u00d73=11\u3068\u306a\u308b\u306f\u305a\u30fb\u30fb\u30fb\u3002<br><br>\u3067\u3059\u304c\u3001\u5b9f\u969b\u306e\u52d5\u4f5c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"808\" height=\"264\" src=\"https:\/\/se-pg-toolbox.com\/wp-content\/uploads\/2024\/01\/article12-1.png\" alt=\"\" class=\"wp-image-184\" \/><\/figure>\n\n\n\n<p>\u6700\u5f8c\u306b\u51fa\u529b\u3057\u305fnum1\u306e\u5024\u304c61\u3068\u3044\u3046\u7d50\u679c\u306b\u306a\u308a\u307e\u3057\u305f\u3002<br><br>\u3053\u308c\u306f\u3069\u3046\u3044\u3046\u3053\u3068\u304b\u3068\u3044\u3046\u3068\u3001\u307e\u305a\u306fcase 2:\u306e\u51e6\u7406\u3092\u901a\u3063\u305f\u5f8c\u3001\u305d\u306e\u307e\u307e case 3:\u3001case 4:\u3001case 5:\u3001default:\u306e\u51e6\u7406\u3092\u901a\u3063\u3066\u3057\u307e\u3044\u3001\u6700\u7d42\u7684\u306b61\u3068\u3044\u3046\u8a08\u7b97\u7d50\u679c\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<br><br><span class=\"marker2\">switch\u6587\u306ecase\u6587\u306e\u6700\u5f8c\u306bbreak;\u3092\u5165\u308c\u306a\u3044\u3068\u3001\u5024\u304c\u4e00\u81f4\u3057\u305fcase\u306e\u5834\u6240\u306b\u79fb\u52d5\u3057\u305f\u5f8c\u3001\u305d\u3053\u304b\u3089\u5f8c\u306e\u51e6\u7406\u3092\u3059\u3079\u3066\u5b9f\u884c\u3057\u3088\u3046\u3068\u3057\u3066\u3057\u307e\u3044\u307e\u3059<\/span>\u3002<br><br>\u3053\u306e\u52d5\u4f5c\u306f<span class=\"marker2\">C\u3084Java\u3092\u4f7f\u3046\u5834\u5408\u306f\u304d\u3061\u3093\u3068\u7406\u89e3\u3057\u3066\u304a\u304b\u306a\u3051\u308c\u3070\u306a\u3089\u305a<\/span>\u3001<span class=\"marker2\">\u77e5\u3089\u305a\u306b\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u3057\u307e\u3046\u3068\u4e88\u60f3\u5916\u306e\u51e6\u7406\u304c\u51fa\u6765\u3066\u3057\u307e\u3046\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059<\/span>\u3002<br><br>\u306a\u306e\u3067\u3001\u7d76\u5bfe\u306b\u4eca\u56de\u66f8\u3044\u305f\u3088\u3046\u306a\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068\u304c\u306a\u3044\u3088\u3046\u306b\u3001\u6b21\u306e\u7ae0\u3067\u7d39\u4ecb\u3059\u308b\u30b3\u30fc\u30c9\u306e\u3088\u3046\u306bbreak;\u3092\u305d\u308c\u305e\u308c\u306ecase\u306b\u5165\u308c\u308b\u3088\u3046\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">switch\u6587\u306ecase:\u306e\u6700\u5f8c\u306bbreak;\u3092\u66f8\u3044\u305f\u5834\u5408<\/h2>\n\n\n\n<p>\u305d\u308c\u3067\u306f\u3001switch\u6587\u306e\u5404case\u306e\u6700\u5f8c\u306bbreak;\u3092\u5165\u308c\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br><br>\u30b3\u30fc\u30c9\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u3044\u3066\u307f\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>\t\/\/switch\u5206\u306ecase:\u5185\u306e\u51e6\u7406\u306bbreak;\u3092\u66f8\u3044\u305f\u5834\u5408\n\tpublic void swBreak() {\n\t\tint num1 = 5;\n\t\tint num2 = 2;\n\t\t\n\t\tswitch(num2) {\n\t\t\t\/\/num2\u304c0\u306e\u5834\u5408\u306fnum2\u3092\u666e\u901a\u306b\u52a0\u7b97\n\t\tcase 0:\n\t\t\tnum1 = num1 + num2;\n\t\t\tbreak;\n\t\t\t\/\/num2\u304c2\u306e\u5834\u5408\u306fnum2\u30923\u500d\u3057\u305f\u3082\u306e\u3092\u52a0\u7b97\n\t\tcase 1:\n\t\t\tnum1 = num1 + num2 * 2;\n\t\t\tbreak;\n\t\t\t\/\/num2\u304c2\u306e\u5834\u5408\u306fnum2\u30923\u500d\u3057\u305f\u3082\u306e\u3092\u52a0\u7b97\n\t\tcase 2:\n\t\t\tnum1 = num1 + num2 * 3;\n\t\t\tbreak;\n\t\t\t\/\/num2\u304c3\u306e\u5834\u5408\u306fnum2\u30924\u500d\u3057\u305f\u3082\u306e\u3092\u52a0\u7b97\n\t\tcase 3:\n\t\t\tnum1 = num1 + num2 * 4;\n\t\t\tbreak;\n\t\t\t\/\/num2\u304c4\u306e\u5834\u5408\u306fnum2\u30925\u500d\u3057\u305f\u3082\u306e\u3092\u52a0\u7b97\n\t\tcase 4:\n\t\t\tnum1 = num1 + num2 * 5;\n\t\t\tbreak;\n\t\t\t\/\/num2\u304c5\u306e\u5834\u5408\u306fnum2\u30926\u500d\u3057\u305f\u3082\u306e\u3092\u52a0\u7b97\n\t\tcase 5:\n\t\t\tnum1 = num1 + num2 * 6;\n\t\t\tbreak;\n\t\t\t\/\/num2\u304c1\uff5e5\u306e\u3044\u305a\u308c\u3067\u3082\u306a\u3044\u5834\u5408\u306fnum2\u309210\u500d\u3057\u305f\u3082\u306e\u3092\u52a0\u7b97\n\t\tdefault:\n\t\t\tnum1 = num1 + num2 * 10;\n\t\t\tbreak;\n\t\t}\n\t\t\/\/\u3053\u3053\u3067\u51fa\u529b\u3055\u308c\u308b\u306e\u306f11\n\t\tSystem.out.println(num1);\n\t}<\/code><\/pre><\/div>\n\n\n\n<p>default:\u306e\u6700\u5f8c\u306ebreak;\u306f\u5fc5\u305a\u66f8\u304b\u306a\u3051\u308c\u3070\u3044\u3051\u306a\u3044\u3082\u306e\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u6163\u7fd2\u7684\u306bbreak;\u3092\u66f8\u3044\u3066\u3044\u308b\u30b3\u30fc\u30c9\u3092\u898b\u308b\u3053\u3068\u304c\u591a\u3044\u306e\u3067\u3001\u3053\u306e\u30b3\u30fc\u30c9\u3067\u3082default:\u306e\u6700\u5f8c\u306bbreak;\u3092\u5165\u308c\u3066\u3044\u307e\u3059\u3002<br><br>\u3067\u306f\u3001\u52d5\u4f5c\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"798\" height=\"259\" src=\"https:\/\/se-pg-toolbox.com\/wp-content\/uploads\/2024\/01\/article12-2.png\" alt=\"\" class=\"wp-image-185\" \/><\/figure>\n\n\n\n<p>\u3053\u306e\u3088\u3046\u306b\u3001case 2:\u306e\u90e8\u5206\u3060\u3051\u901a\u3063\u3066\u3001switch\u6587\u3092\u7d42\u4e86\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u5206\u304b\u308a\u307e\u3059\u3002<br><br>\u57fa\u672c\u7684\u306bswitch\u6587\u3092\u8907\u6570\u306ecase\u306b\u6e21\u3063\u3066\u51e6\u7406\u3055\u305b\u308b\u3053\u3068\u306f\u7a00\u3067\u3059\u3057\u3001\u30bd\u30fc\u30b9\u306e\u53ef\u8aad\u6027\u306e\u554f\u984c\u3082\u3042\u308b\u305f\u3081\u3001\u7d76\u5bfe\u306b\u305d\u3093\u306a\u66f8\u304d\u65b9\u306f\u3057\u3066\u306f\u3044\u3051\u307e\u305b\u3093\u3002<br><br><span class=\"marker2\">switch\u6587\u3092\u66f8\u304f\u6642\u306f\u305d\u308c\u305e\u308c\u306ecase\u3067\u5b8c\u7d50\u3059\u308b<\/span>\u3002<br><br>\u3053\u306e\u8003\u3048\u65b9\u306f\u5b9f\u969b\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u304f\u6642\u306b\u306f\u7d76\u5bfe\u306b\u610f\u8b58\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br><br>break;\u6587\u3092\u66f8\u304d\u5fd8\u308c\u308b\u3068\u3001switch\u6587\u3092\u4f7f\u3063\u3066\u3082\u671f\u5f85\u3057\u305f\u52d5\u4f5c\u306b\u306a\u3089\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u4eca\u56de\u306fswitch\u6587\u306ecase\u5185\u306ebreak;\u306b\u3064\u3044\u3066\u304a\u8a71\u3057\u3057\u307e\u3057\u305f\u3002<br><br>\u4eca\u56de\u899a\u3048\u3066\u304a\u304d\u305f\u3044\u70b9\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>switch\u6587\u3092\u66f8\u304f\u306e\u3067\u3042\u308c\u3070\u3001case\u5185\u306ebreak;\u306f\u5fc5\u305a\u66f8\u304f\uff08\u304a\u307e\u3058\u306a\u3044\u30ec\u30d9\u30eb\u3067\u899a\u3048\u3066\u304a\u304f\u3053\u3068\uff09\u3002<\/li>\n\n\n\n<li>case\u5185\u306ebreak;\u3092\u66f8\u304d\u5fd8\u308c\u308b\u3068\u6b21\u306ecase\u306e\u51e6\u7406\u3092\u7d9a\u3051\u3066\u51e6\u7406\u3057\u3066\u3057\u307e\u3046<\/li>\n\n\n\n<li>\u8907\u6570\u306ecase:\u306b\u6e21\u308b\u51e6\u7406\u306f\u66f8\u304b\u305a\u30011\u3064\u306ecase\u5185\u3067\u51e6\u7406\u3092\u5b8c\u7d50\u3059\u308b\u3088\u3046\u306b\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3053\u3068<\/li>\n<\/ol>\n\n\n\n<p>\u4eca\u56de\u306e\u5185\u5bb9\u306f\u57fa\u790e\u7684\u306a\u3082\u306e\u3067\u3001\u300c\u8a00\u308f\u308c\u306a\u304f\u3066\u3082\u5206\u304b\u3063\u3066\u3044\u308b\u300d\u3068\u601d\u308f\u308c\u308b\u65b9\u3082\u591a\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<br><br>\u3057\u304b\u3057\u3001\u3053\u306e\u3088\u3046\u306a\u57fa\u790e\u77e5\u8b58\u3092\u3057\u3063\u304b\u308a\u7406\u89e3\u3057\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u304c\u3001\u5b9f\u52d9\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u304f\u4e0a\u3067\u91cd\u8981\u306b\u306a\u3063\u3066\u304d\u307e\u3059\u3002<br><br>\u5b66\u6821\u3067\u306e\u6f14\u7fd2\u3067\u306f\u30df\u30b9\u3057\u3066\u3082\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u5b9f\u52d9\u3067\u30df\u30b9\u3092\u8d77\u3053\u3059\u3068\u30d0\u30b0\u306b\u7e4b\u304c\u308a\u307e\u3059\u3002<br><br>break;\u306e\u5165\u308c\u5fd8\u308c\u306f\u898b\u3064\u3051\u306b\u304f\u3044\u30d0\u30b0\u306b\u306f\u306a\u308a\u307e\u305b\u3093\u304c\u3001\u5fc5\u305aswitch\u6587\u306ecase\u306b\u306fbreak;\u3092\u5165\u308c\u308b\u3053\u3068\u3092\u5fd8\u308c\u305a\u306b\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u610f\u8b58\u3092\u6301\u3064\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n\n\n\n<p><span class=\"marker\">\u4eca\u56de\u306e\u8a18\u4e8b\u306f\u3053\u3053\u307e\u3067\u3068\u306a\u308a\u307e\u3059\u3002<br>\u307e\u305f\u6b21\u56de\u306e\u8a18\u4e8b\u3067\u304a\u4f1a\u3044\u3057\u307e\u3057\u3087\u3046\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>if\u6587\u3067\u591a\u304f\u306e\u5206\u5c90\u304c\u767a\u751f\u3057\u3001else if\u3092\u4f55\u5ea6\u3082\u66f8\u304b\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u5834\u5408\u3001switch\u6587\u3092\u4f7f\u3063\u3066\u898b\u3084\u3059\u304f\u66f8\u304f\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002 \u3057\u304b\u3057\u3001switch\u6587\u3092\u66f8\u304f\u306b\u3042\u305f\u3063\u3066\u898b\u843d\u3068\u3057\u3084\u3059\u3044\u70b9\u304c\u3042\u308a\u307e\u3059\u3002 \u305d\u308c\u306fcase\u306e\u6700\u5f8c\u306bbr<\/p>\n","protected":false},"author":2,"featured_media":160,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jin_ogp_image_url":"","_jin_last_featured_id":0,"footnotes":""},"categories":[9,5],"tags":[15,4,12],"class_list":["post-183","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-5","tag-java","tag-4","tag-12"],"_links":{"self":[{"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/posts\/183","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=183"}],"version-history":[{"count":1,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/posts\/183\/revisions"}],"predecessor-version":[{"id":186,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/posts\/183\/revisions\/186"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=\/wp\/v2\/media\/160"}],"wp:attachment":[{"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/se-pg-toolbox.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}