{"id":126,"date":"2017-02-18T23:11:00","date_gmt":"2017-02-18T15:11:00","guid":{"rendered":"https:\/\/cn1.club\/?p=126"},"modified":"2025-03-13T20:11:08","modified_gmt":"2025-03-13T12:11:08","slug":"day3-%e7%ac%94%e8%ae%b0%e7%bb%83%e4%b9%a0-%e9%80%89%e6%8b%a9%e7%bb%93%e6%9e%84if%e8%af%ad%e5%8f%a5%e5%92%8cswitch%e8%af%ad%e5%8f%a5%e7%9a%84%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"http:\/\/cn1.club\/?p=126","title":{"rendered":"Day3 \u7b14\u8bb0\u7ec3\u4e60 \u9009\u62e9\u7ed3\u6784if\u8bed\u53e5\u548cSwitch\u8bed\u53e5\u7684\u533a\u522b"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >import java.util.Scanner;\nclass Test3_SwitchIf {\n\tpublic static void main(String&#091;] args) {\n\t\t\/*Scanner sc = new Scanner(System.in);\n\t\tSystem.out.println(&quot;\u8bf7\u8f93\u5165\u60a8\u60f3\u67e5\u8be2\u6708\u4efd\u7684\u5b63\u8282!\u8303\u56f4&#091;1-12]&quot;);\n\t\t\/*\n\t\t\u4e00\u5e74\u6709\u56db\u5b63\n\t\t3,4,5 \u6625\u5b63\n\t\t6,7,8 \u590f\u5b63\n\t\t9,10,11 \u79cb\u5b63\n\t\t12,1,2 \u51ac\u5b63\n\t\t\n\t\tint x = sc.nextInt();\n\t\tswitch (x) {\n\t\tcase 1:\n\t\t\tSystem.out.println(&quot;\u51ac\u5b63&quot;);\n\t\tbreak;\n\t\tcase 2:\n\t\t\tSystem.out.println(&quot;\u51ac\u5b63&quot;);\n\t\tbreak;\n\t\tcase 3:\n\t\t\tSystem.out.println(&quot;\u6625\u5b63&quot;);\n\t\tbreak;\n\t\tcase 4:\n\t\t\tSystem.out.println(&quot;\u6625\u5b63&quot;);\n\t\tbreak;\n\t\tcase 5:\n\t\t\tSystem.out.println(&quot;\u6625\u5b63&quot;);\n\t\tbreak;\n\t\tcase 6:\n\t\t\tSystem.out.println(&quot;\u590f\u5b63&quot;);\n\t\tbreak;\n\t\tcase 7:\n\t\t\tSystem.out.println(&quot;\u590f\u5b63&quot;);\n\t\tbreak;\n\t\tcase 8:\n\t\t\tSystem.out.println(&quot;\u590f\u5b63&quot;);\n\t\tbreak;\n\t\tcase 9:\n\t\t\tSystem.out.println(&quot;\u79cb\u5b63&quot;);\n\t\tbreak;\n\t\tcase 10:\n\t\t\tSystem.out.println(&quot;\u79cb\u5b63&quot;);\n\t\tbreak;\n\t\tcase 11:\n\t\t\tSystem.out.println(&quot;\u79cb\u5b63&quot;);\n\t\tbreak;\n\t\tdefault:\n\t\t\tSystem.out.println(&quot;\u60a8\u8f93\u5165\u4e86\u8303\u56f4\u4e4b\u5916\u7684\u503c!&quot;);\n\t\t\n\t\t}\n\n\n\n\t\t=====================================\n\t\t\u518d\u6548\u7387\u4e9b\u7684\u65b9\u6cd5:\u5229\u7528case\u7a7f\u900f: 345   678   9 10 11   12 1 2\n\t\t\n\t\tcase 3:\n\t\tcase 4:\n\t\tcase 5:\n\t\t\tSystem.out.println(&quot;\u6625\u5b63&quot;);\n\t\tbreak;\n\t\tcase 6:\n\t\tcase 7:\n\t\tcase 8:\n\t\t\tSystem.out.println(&quot;\u590f\u5b63&quot;);\n\t\tbreak;\n\t\t=====================================\n\t\t*\/\n\n\n\n\n\n\n\n\n\t\t\/\/\u7b2c\u4e8c\u79cd\u65b9\u5f0fIf\u8bed\u53e5\n\n\n\n\n\n\t\tScanner sc = new Scanner(System.in);\n\t\tSystem.out.println(&quot;\u8bf7\u8f93\u5165\u60a8\u60f3\u67e5\u8be2\u6708\u4efd\u7684\u5b63\u8282!\u8303\u56f4&#091;1-12]&quot;);\n\t\tint x = sc.nextInt();\n\t\tif (x &lt;= 2) {\n\t\t\tSystem.out.println(&quot;\u51ac\u5b63&quot;);\n\t\t}else if (x &lt;= 5 &amp;&amp; x &gt;= 3) {\n\t\t\tSystem.out.println(&quot;chunji&quot;);\n\t\t}else if (x &lt;= 8 &amp;&amp; x &gt;= 6) {\n\t\t\tSystem.out.println(&quot;\u590f\u5b63&quot;);\n\t\t}else if (x &lt;= 9 &amp;&amp; x &gt;= 11) {\n\t\t\tSystem.out.println(&quot;\u79cb\u5b63&quot;);\n\t\t}else if (x == 12) {\n\t\t\tSystem.out.println(&quot;\u51ac\u5b63&quot;);\n\t\t}else{\n\t\t\tSystem.out.println(&quot;\u8f93\u5165\u7684\u503c\u4e0d\u5728\u8303\u56f4 &quot;);\n\t\t}\n\n\n\n\n\n\n\t\/*=================================\n\tif (x &gt; 12 || x &lt; 1) {\n\t\t\tSystem.out.println(&quot;\u6ca1\u6709\u5bf9\u5e94\u7684\u5b63\u8282&quot;);\n\t\t}else if (x &lt;= 5 &amp;&amp; x &gt;= 3) {\n\t\t\tSystem.out.println(&quot;chunji&quot;);\n\t\t}else if (x &lt;= 8 &amp;&amp; x &gt;= 6) {\n\t\t\tSystem.out.println(&quot;\u590f\u5b63&quot;);\n\t\t}else if (x &lt;= 9 &amp;&amp; x &gt;= 11) {\n\t\t\tSystem.out.println(&quot;\u79cb\u5b63&quot;);\n\t\t}else {\n\t\t\tSystem.out.println(&quot;\u51ac\u5b63&quot;);\n\t\t}\n\t}\n\t\t\u6b64\u65b9\u6cd5\u4e3a\u8001\u5e08\u7684\u65b9\u6cd5,\u4ee3\u7801\u7b80\u6d01\u9ad8\u6548.\n\t\t\u5e94\u8be5\u819c\u62dc\u5b66\u4e60\n\t\/\/=================================*\/\n\t}\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":196,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"class_list":["post-126","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-xuexi"],"_links":{"self":[{"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/posts\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=126"}],"version-history":[{"count":0,"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/posts\/126\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=\/wp\/v2\/media\/196"}],"wp:attachment":[{"href":"http:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/cn1.club\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}