{"id":79,"date":"2024-02-20T04:24:32","date_gmt":"2024-03-08T08:01:30","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/index.php\/2023\/11\/30\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/"},"modified":"2025-07-31T22:32:26","modified_gmt":"2025-07-31T14:32:26","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/","title":{"rendered":"Java\u6761\u4ef6\u8bed\u53e5\u7cbe\u901a\u6307\u5357\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528"},"content":{"rendered":"<p>\u4f5c\u8005\u9009\u62e9\u4e3a\u5199\u4f5c\u6309\u6350\u8d60\u8ba1\u5212\u4e4b\u4e00\u6350\u8d60\u6b3e\u9879\u7ed9\u81ea\u7531\u5f00\u6e90\u57fa\u91d1\u3002<\/p>\n<h3>\u5f15\u8a00<\/h3>\n<p>\u6761\u4ef6\u8bed\u53e5\u6539\u53d8\u7a0b\u5e8f\u7684\u6d41\u7a0b\u3002\u6761\u4ef6\u8bed\u53e5\u4e5f\u88ab\u79f0\u4e3a\u5206\u652f\u8bed\u53e5\uff0c\u56e0\u4e3a\u5f53\u6761\u4ef6\u5339\u914d\u65f6\uff0c\u6d41\u7a0b\u4f1a\u8fdb\u5165\u4ee3\u7801\u7684\u4e00\u4e2a\u5206\u652f\u3002\u5982\u679c\u6761\u4ef6\u4e0d\u6ee1\u8db3\uff0c\u5219\u4f1a\u8bc4\u4f30\u53e6\u4e00\u4e2a\u6761\u4ef6\uff08\u5982\u679c\u6709\u7684\u8bdd\uff09\u3002\u8be5\u8bc4\u4f30\u4f1a\u7ee7\u7eed\uff0c\u76f4\u5230\u6240\u6709\u6761\u4ef6\u90fd\u88ab\u8bc4\u4f30\u4e3a\u771f\u6216\u5047\u4e3a\u6b62\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6761\u4ef6\u8bed\u53e5\u6765\u6bd4\u8f83\u4e24\u4e2a\u6570\u5b57\uff08x\u548cy\uff09\uff1ax > y\u3001x = y\u548cx < y\u3002\u5982\u679cx\u7b49\u4e8e1\uff0cy\u7b49\u4e8e2\uff0c\u5219\u4f1a\u8fdb\u884c\u4e09\u6b21\u8bc4\u4f30\uff0c\u76f4\u5230\u6700\u7ec8\u7684x < y\u6761\u4ef6\u8bed\u53e5\u8bc4\u4f30\u4e3a\u771f\u3002<\/p>\n<p>\u6709\u4e24\u79cd\u6761\u4ef6\u8bed\u53e5\u3002\u7b2c\u4e00\u79cd\u7c7b\u578b\u662f<code>if<\/code>\u4ee5\u53ca\u5b83\u7684\u6269\u5c55\u5f62\u5f0f<code>else if<\/code>\u3002\u8fd9\u79cd\u7c7b\u578b\u88ab\u5e7f\u6cdb\u4f7f\u7528\u3002\u7b2c\u4e8c\u79cd\u7c7b\u578b\u662f<code>switch<\/code>\uff0c\u66f4\u5177\u4f53\u4e14\u9650\u5236\u8f83\u591a\u3002<\/p>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u4f60\u5c06\u4f1a\u7528Java\u7f16\u5199\u6761\u4ef6\u8bed\u53e5\uff0c\u5e76\u5b66\u4e60\u6bcf\u79cd\u7c7b\u578b\u7684\u4f7f\u7528\u60c5\u51b5\u3001\u4f18\u70b9\u548c\u7f3a\u70b9\u3002<\/p>\n<h2>\u5148\u51b3\u6761\u4ef6<\/h2>\n<p>\u8981\u8ddf\u968f\u672c\u6559\u7a0b\uff0c\u60a8\u9700\u8981\uff1a<\/p>\n<ul class=\"post-ul\">\n<li>\u4e00\u4e2a\u53ef\u4ee5\u6267\u884cJava\u7a0b\u5e8f\u7684\u73af\u5883\uff0c\u4ee5\u4fbf\u8ddf\u968f\u793a\u4f8b\u3002\u8981\u5728\u60a8\u7684\u672c\u5730\u673a\u5668\u4e0a\u8fdb\u884c\u8bbe\u7f6e\uff0c\u60a8\u5c06\u9700\u8981\u4ee5\u4e0b\u5185\u5bb9\uff1a\n<p>\u60a8\u7684\u673a\u5668\u4e0a\u5b89\u88c5\u4e86Java\uff08\u7248\u672c11\u6216\u66f4\u9ad8\uff09\uff0c\u5e76\u5e26\u6709Java\u5f00\u53d1\u5de5\u5177\u5305\uff08JDK\uff09\u63d0\u4f9b\u7684\u7f16\u8bd1\u5668\u3002\u5bf9\u4e8eUbuntu\u548cDebian\uff0c\u8bf7\u9075\u5faa\u6211\u4eec\u6559\u7a0b\u300a\u5982\u4f55\u5728Ubuntu 22.04\u4e0a\u4f7f\u7528Apt\u5b89\u88c5Java\u300b\u4e2d\u9009\u98791\u7684\u6b65\u9aa4\u3002\u5bf9\u4e8e\u5176\u4ed6\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5305\u62ecMac\u548cWindows\uff0c\u8bf7\u9075\u5faaJava\u5b89\u88c5\u7684\u4e0b\u8f7d\u9009\u9879\u3002<br \/>\u4e3a\u4e86\u7f16\u8bd1\u548c\u8fd0\u884c\u4ee3\u7801\u793a\u4f8b\uff0c\u672c\u6559\u7a0b\u4f7f\u7528Java Shell\uff0c\u5b83\u662f\u4e00\u4e2a\u4ece\u547d\u4ee4\u884c\u8fd0\u884c\u7684\u8bfb\u53d6-\u8bc4\u4f30-\u6253\u5370\u5faa\u73af\uff08REPL\uff09\u3002\u8981\u5f00\u59cb\u4f7f\u7528JShell\uff0c\u8bf7\u67e5\u9605\u300aJShell\u7b80\u4ecb\u300b\u6307\u5357\u3002<\/li>\n<li>\u719f\u6089Java\u548c\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff0c\u60a8\u53ef\u4ee5\u5728\u6211\u4eec\u7684\u6559\u7a0b\u300a\u5982\u4f55\u7f16\u5199\u60a8\u7684\u7b2c\u4e00\u4e2aJava\u7a0b\u5e8f\u300b\u4e2d\u627e\u5230\u3002<\/li>\n<li>\u7406\u89e3Java\u6570\u636e\u7c7b\u578b\uff0c\u8fd9\u5728\u6211\u4eec\u7684\u6559\u7a0b\u300a\u7406\u89e3Java\u4e2d\u7684\u6570\u636e\u7c7b\u578b\u300b\u4e2d\u6709\u6240\u8ba8\u8bba\u3002<\/li>\n<\/ul>\n<h2>\u533a\u5206\u8bed\u53e5\u548c\u5757<\/h2>\n<p>\u5f53\u6ee1\u8db3\u6761\u4ef6\u8bed\u53e5\u5e76\u4e14\u6267\u884c\u6d41\u7a0b\u88ab\u5f15\u5bfc\u5230\u76f8\u5e94\u7684\u4ee3\u7801\u5206\u652f\u65f6\uff0c\u8be5\u5206\u652f\u53ef\u4ee5\u662f\u5355\u4e2a\u8bed\u53e5\u6216\u4e00\u5757\u4ee3\u7801\u3002\u7531\u4e8e\u8bed\u53e5\u548c\u4ee3\u7801\u5757\u7684\u5904\u7406\u65b9\u5f0f\u4e0d\u540c\uff0c\u56e0\u6b64\u533a\u5206\u5b83\u4eec\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<p>\u4e00\u6761\u8bed\u53e5\u662f\u4e00\u4e2a\u6267\u884c\u5355\u5143\uff0c\u901a\u5e38\u4ee5\u5206\u53f7\u7ed3\u675f\uff0c\u53ea\u5360\u7528\u4e00\u884c\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u4e0b\u9762\u7684\u8bed\u53e5\u6253\u5370\u793a\u4f8b\uff1a<\/p>\n<pre class=\"post-pre\"><code><ol><li data-prefix=\"jshell>\">System.out.println<span class=\"token punctuation\">(<\/span><span class=\"token string\">\"example\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li><\/ol><\/code><\/pre>\n<div class=\"post-conf-info\">\n<p class=\"post-info\">\n<p class=\"post-conf-desc\">\u4fe1\u606f<\/p>\n<div>\n<p>\u4e3a\u4e86\u8ddf\u968f\u672c\u6559\u7a0b\u4e2d\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u901a\u8fc7\u8fd0\u884c<code>jshell<\/code>\u547d\u4ee4\u5728\u60a8\u7684\u672c\u5730\u7cfb\u7edf\u4e0a\u6253\u5f00Java Shell\u5de5\u5177\u3002\u7136\u540e\u53ef\u4ee5\u901a\u8fc7\u5728<code>jshell><\/code>\u63d0\u793a\u7b26\u540e\u6dfb\u52a0\u5e76\u6309ENTER\u8fdb\u884c\u590d\u5236\u3001\u7c98\u8d34\u6216\u7f16\u8f91\u793a\u4f8b\u3002\u8981\u9000\u51fajshell\uff0c\u8bf7\u8f93\u5165<code>\/exit<\/code>\u3002<\/p>\n<\/div>\n<\/div>\n<p>\u6b64\u8bed\u53e5\u4f7f\u7528<code>println()<\/code>\u65b9\u6cd5\u6765\u6253\u5370\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5728\u8fd9\u4e2a\u6848\u4f8b\u4e2d\u4e3a\u201cexample\u201d\u3002\u9664\u975e\u53e6\u6709\u6307\u793a\uff0cJava\u5c06\u65e0\u6761\u4ef6\u6267\u884c\u6b64\u8bed\u53e5\u3002<\/p>\n<div class=\"post-conf-note\">\n<p class=\"post-note\">\n<p class=\"post-conf-desc\">\u6ce8\u610f<\/p>\n<div>\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u4e3a\u4e86\u4f7f\u8bed\u53e5\u66f4\u6613\u8bfb\uff0c\u4f1a\u5c06\u5176\u5199\u5728\u4e00\u884c\u4e0a\u3002\u7136\u800c\uff0c\u6839\u636e\u5b98\u65b9\u7ea6\u5b9a\u6307\u5357\uff0c\u5e94\u907f\u514d\u8d85\u8fc780\u4e2a\u5b57\u7b26\u7684\u884c\u3002\u5982\u679c\u60a8\u7684\u8bed\u53e5\u8d85\u8fc780\u4e2a\u5b57\u7b26\uff0c\u5e94\u5c06\u5176\u62c6\u5206\u6210\u591a\u884c\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5982\u4f7f\u7528lambda\u8868\u8fbe\u5f0f\u65f6\uff0c\u5c06\u8bed\u53e5\u5206\u6563\u5230\u51e0\u884c\u4e2d\u66f4\u65b9\u4fbf\u3001\u76f4\u89c2\u3002\u65e0\u8bba\u5982\u4f55\uff0cJava\u5bf9\u8bed\u53e5\u4e2d\u7684\u6362\u884c\u6ca1\u6709\u8bed\u6cd5\u8981\u6c42\uff0c\u60a8\u53ef\u4ee5\u5728\u65b0\u7684\u4e00\u884c\u4e0a\u7ee7\u7eed\u8bed\u53e5\u3002\u4f5c\u4e3a\u7ec3\u4e60\uff0c\u5c1d\u8bd5\u91cd\u5199\u672c\u6559\u7a0b\u4e2d\u7684\u67d0\u4e9b\u793a\u4f8b\uff0c\u5e76\u5c06\u8bed\u53e5\u5206\u9694\u5230\u591a\u884c\u4e0a\u3002<\/p>\n<\/div>\n<\/div>\n<p>\u5f53\u4f60\u5c06\u8bed\u53e5\u5206\u7ec4\u4ee5\u4fbf\u4e00\u8d77\u6267\u884c\u65f6\uff0c\u4f60\u4f7f\u7528\u7684\u662f\u4e00\u4e2a\u4ee3\u7801\u5757\u3002\u4ee3\u7801\u5757\u662f\u4ee5\u5de6\u5927\u62ec\u53f7\uff08<code>{<\/code>\uff09\u5f00\u5934\uff0c\u4ee5\u53f3\u5927\u62ec\u53f7\uff08<code>}<\/code>\uff09\u7ed3\u5c3e\u7684\u96f6\u4e2a\u6216\u591a\u4e2a\u8bed\u53e5\u7684\u96c6\u5408\u3002\u4f60\u53ef\u4ee5\u50cf\u4e0b\u9762\u8fd9\u6837\u91cd\u65b0\u5199\u524d\u9762\u7684\u4ee3\u7801\u5e76\u5c06\u5176\u653e\u5165\u4e00\u4e2a\u4ee3\u7801\u5757\u4e2d\uff1a<\/p>\n<pre class=\"post-pre\"><code><ol><li data-prefix=\"jshell>\"><span class=\"token punctuation\">{<\/span><\/li><li data-prefix=\"jshell>\">    System.out.println<span class=\"token punctuation\">(<\/span><span class=\"token string\">\"example\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"jshell>\"><span class=\"token punctuation\">}<\/span><\/li><\/ol><\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u5757\u4e2d\uff0c\u60a8\u5728<code>System.out.println(\"example\");<\/code>\u4e4b\u524d\u4f7f\u7528\u4e86\u56db\u4e2a\u7a7a\u683c\u3002\u8fd9\u56db\u4e2a\u7a7a\u683c\u88ab\u79f0\u4e3a\u7f29\u8fdb\u3002\u4e0ePython\u7b49\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u4e0d\u540c\uff0c\u5728Java\u4e2d\u7f29\u8fdb\u65e2\u4e0d\u662f\u5fc5\u9700\u7684\uff0c\u4e5f\u4e0d\u4f1a\u5f71\u54cd\u4ee3\u7801\u3002\u7136\u800c\uff0c\u4e3a\u4e86\u66f4\u597d\u7684\u53ef\u8bfb\u6027\uff0c\u5e76\u4e14\u6309\u7167\u7ea6\u5b9a\uff0c\u5757\u5185\u7684\u4ee3\u7801\u884c\u4ee5\u56db\u4e2a\u7a7a\u683c\u7684\u7f29\u8fdb\u5f00\u59cb\u3002\u5927\u591a\u6570\u4ee3\u7801\u7f16\u8f91\u5668\u90fd\u652f\u6301\u81ea\u52a8\u7f29\u8fdb\uff0c\u4f46\u662f\u7ea6\u5b9a\u5728\u4e0d\u540c\u7684\u7f16\u7a0b\u8bed\u8a00\u751a\u81f3\u7f16\u8f91\u5668\u4e4b\u95f4\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002\u56e0\u6b64\uff0c\u5982\u679c\u60a8\u7684\u4ee3\u7801\u7f16\u8f91\u5668\u652f\u6301\u7f29\u8fdb\uff0c\u8bf7\u786e\u4fdd\u5728\u7f16\u5199Java\u4ee3\u7801\u65f6\u5c06\u5176\u8bbe\u7f6e\u4e3a\u56db\u4e2a\u7a7a\u683c\u3002Jshell\u5728\u672c\u6559\u7a0b\u4e2d\u63a8\u8350\u4f7f\u7528\uff0c\u5e76\u81ea\u52a8\u5c06\u56db\u4e2a\u7a7a\u683c\u8bbe\u7f6e\u4e3a\u7f29\u8fdb\u3002<\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5c06\u4ee3\u7801\u653e\u5728\u4e00\u4e2a\u5757\u5185\u4e0d\u4f1a\u6709\u4efb\u4f55\u533a\u522b\uff0c\u56e0\u4e3a\u6ca1\u6709\u6761\u4ef6\u3002\u56e0\u6b64\uff0c\u65e0\u8bba\u8bed\u53e5\u662f\u5426\u5728\u5757\u5185\uff0c\u793a\u4f8b\u90fd\u5c06\u88ab\u6253\u5370\u51fa\u6765\u3002\u5f53\u4f60\u5728jshell\u4e2d\u8fd0\u884c\u8fd9\u4e24\u4e2a\u5148\u524d\u7684\u793a\u4f8b\u65f6\uff0c\u4f60\u5c06\u5728\u4e24\u79cd\u60c5\u51b5\u4e0b\u6536\u5230\u76f8\u540c\u7684\u8f93\u51fa\u3002<\/p>\n<pre class=\"post-pre\"><code><div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>example<\/code><\/pre>\n<p>\u4ee5\u4e0a\u7684\u8f93\u51fa\u7ed3\u679c\u663e\u793a\uff0c\u5728\u4e00\u4e2a\u4ee3\u7801\u5757\u5185\u6216\u8005\u5728\u4ee3\u7801\u5757\u5916\u9762\u6253\u5370\u793a\u4f8b\u7684\u8bed\u53e5\u662f\u4ee5\u76f8\u540c\u7684\u65b9\u5f0f\u5de5\u4f5c\u7684\u3002<\/p>\n<p>\u5728\u672c\u8282\u4e2d\uff0c\u60a8\u4e86\u89e3\u5230\u4e86\u8bed\u53e5\u3001\u4ee3\u7801\u5757\u4ee5\u53ca\u5982\u4f55\u521b\u5efa\u5b83\u4eec\u3002\u4e0b\u4e00\u8282\u4e2d\uff0c\u60a8\u5c06\u5411\u4ee3\u7801\u5757\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u6761\u4ef6\u8bed\u53e5\u3002\u56e0\u6b64\uff0c\u4ee3\u7801\u5757\u5185\u7684\u8bed\u53e5\u5c06\u4f1a\u4e00\u8d77\u5e76\u4e14\u6709\u6761\u4ef6\u5730\u6267\u884c\u3002<\/p>\n<h2>\u4f7f\u7528\u5355\u4e00\u7684\u6761\u4ef6\u8bed\u53e5<\/h2>\n<p>\u6700\u5e38\u7528\u7684\u6761\u4ef6\u8bed\u53e5\u662f<code>if<\/code>\u8bed\u53e5\u3002\u53ea\u8981\u6bd4\u8f83\u7ed3\u679c\u662f\u5e03\u5c14\u503c\uff08\u771f\u6216\u5047\uff09\uff0c\u5b83\u5c31\u662f\u901a\u7528\u7684\u5e76\u6ee1\u8db3\u6240\u6709\u6761\u4ef6\u6bd4\u8f83\u7684\u9700\u6c42\u3002<code>if<\/code>\u6761\u4ef6\u8bed\u53e5\u53ef\u4ee5\u662f\u6700\u7b80\u5355\u5f62\u5f0f\u7684\u5355\u4e00\u6761\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u6709\u66f4\u590d\u6742\u7684\u7ed3\u6784\uff0c\u5728\u540e\u9762\u7684\u90e8\u5206\u4e2d\u4f60\u5c06\u4f1a\u4f7f\u7528\u5230\u3002<\/p>\n<p>\u5355\u4e2a<code>if<\/code>\u8bed\u53e5\u7528\u4e8e\u5728\u5355\u4e2a\u6761\u4ef6\u4e0b\u6267\u884c\u4e00\u6bb5\u4ee3\u7801\u3002\u60a8\u5c06\u4f1a\u5c06\u6761\u4ef6\u6267\u884c\u7684\u4ee3\u7801\u653e\u5728\u4e00\u4e2a\u4ee3\u7801\u5757\u4e2d\uff0c\u5e76\u5728\u5f00\u5934\u653e\u7f6e<code>if (\u5e03\u5c14\u8868\u8fbe\u5f0f)<\/code>\u3002\u53ea\u6709\u5f53\u8868\u8fbe\u5f0f\u53ca\u5176\u6761\u4ef6\u4e3a\u771f\u65f6\uff0c\u4ee3\u7801\u5757\u624d\u4f1a\u88ab\u6267\u884c\u3002\u5982\u679c\u8868\u8fbe\u5f0f\u7684\u7ed3\u679c\u4e3a\u5047\uff0c\u5219\u6761\u4ef6\u5757\u7684\u4ee3\u7801\u5c06\u88ab\u8df3\u8fc7\u3002<\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f60\u5c06\u7f16\u5199\u4e00\u4e2a\u4ee3\u7801\u7247\u6bb5\u6765\u6bd4\u8f83\u4e24\u4e2a\u6570\u5b57\u3002\u6839\u636e\u6bd4\u8f83\u7684\u7ed3\u679c\uff0c\u53ef\u80fd\u4f1a\u6253\u5370\u4e00\u6761\u6d88\u606f\u3002\u5c06\u4ee5\u4e0b\u884c\u6dfb\u52a0\u5230jshell\u4e2d\uff1a<\/p>\n<pre class=\"post-pre\"><code><ol><li data-prefix=\"1\"><span class=\"token keyword\">int<\/span> x <span class=\"token operator\">=<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"2\"><span class=\"token keyword\">int<\/span> y <span class=\"token operator\">=<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"3\"><mark><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">&gt;<\/span> y<span class=\"token punctuation\">)<\/span><\/mark> <span class=\"token punctuation\">{<\/span><\/li><li data-prefix=\"4\">    <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">+<\/span> <span class=\"token string\">\" is bigger than \"<\/span> <span class=\"token operator\">+<\/span> y<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"5\"><span class=\"token punctuation\">}<\/span><\/li><\/ol><\/code><\/pre>\n<p>\u5728\u524d\u4e24\u884c\u4e2d\uff0c\u60a8\u5b9a\u4e49\u4e86\u4e24\u4e2a\u53d8\u91cf\uff1a<code>x<\/code>\u548c<code>y<\/code>\u3002\u7b2c\u4e09\u884c\u662f\u6761\u4ef6\u8bed\u53e5<code>if (x > y)<\/code>\uff0c\u5b83\u6bd4\u8f83\u4e86<code>x<\/code>\u662f\u5426\u5927\u4e8e<code>y<\/code>\u3002\u6bd4\u8f83\u64cd\u4f5c\u901a\u5e38\u4f4d\u4e8e\u62ec\u53f7\u4e2d\u3002<\/p>\n<p>\u5757\u4ee3\u7801\u4ee5\u7b2c\u4e00\u4e2a\u5f00\u62ec\u53f7\uff08<code>{<\/code>\uff09\u5f00\u59cb\uff0c\u4ee5\u95ed\u62ec\u53f7\uff08<code>}<\/code>\uff09\u7ed3\u675f\u3002\u5728\u5757\u5185\uff0c\u4e00\u4e2a\u8bed\u53e5\u4f7f\u7528<code>println()<\/code>\u65b9\u6cd5\u6765\u6253\u5370\u51fa\u201cx\u5927\u4e8ey\u201d\u3002\u53ea\u6709\u5f53\u8fd9\u4e2a\u6761\u4ef6\u4e3a\u771f\u65f6\uff0c\u5757\u4ee3\u7801\u624d\u4f1a\u88ab\u6267\u884c\u3002<\/p>\n<p>\u5f53\u4f60\u5728jshell\u4e2d\u8fd0\u884c\u6b64\u4ee3\u7801\u65f6\uff0c\u5c06\u4f1a\u5f97\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<p>\u8fd9\u662f\u6587\u7ae0\u300a\u5982\u4f55\u5728Java\u4e2d\u7f16\u5199\u6761\u4ef6\u8bed\u53e5\u300b\u7684\u7b2c2\u90e8\u5206\uff08\u51715\u90e8\u5206\uff09\u3002<\/p>\n<pre class=\"post-pre\"><code><div class=\"secondary-code-label\" title=\"Output\">Outputx ==&gt; 1\r\ny ==&gt; 0\r\n1 is bigger than 0\r\n<\/code><\/pre>\n<p>\u8f93\u51fa\u7684\u524d\u4e24\u884c\u786e\u8ba4\u4e86x\u548cy\u7684\u503c\u3002\u7b2c\u4e09\u884c\u8868\u793a1\u5927\u4e8e0\uff0c\u8fd9\u610f\u5473\u7740\u6761\u4ef6\u8bed\u53e5\u4e3a\u771f\uff1ax\u5927\u4e8ey\u3002\u5982\u679c\u4f60\u5c06x\u6539\u4e3a\u5c0f\u4e8ey\uff0c\u90a3\u4e48\u8be5\u6d88\u606f\u5c06\u4e0d\u4f1a\u88ab\u6253\u5370\u3002<\/p>\n<p>\u5728\u6761\u4ef6\u8bed\u53e5\u4e2d\uff0c\u6700\u91cd\u8981\u7684\u89c4\u5219\u662f\u8bc4\u4f30\u7684\u8868\u8fbe\u5f0f\u5fc5\u987b\u8fd4\u56de\u4e00\u4e2a\u5e03\u5c14\u503c\u3002\u5426\u5219\uff0c\u5728\u4efb\u4f55\u5176\u4ed6\u60c5\u51b5\u4e0b\uff0c\u90fd\u4f1a\u51fa\u73b0\u9519\u8bef\uff0c\u56e0\u4e3a\u4f60\u6240\u6bd4\u8f83\u7684\u5185\u5bb9\u65e0\u6cd5\u8f6c\u6362\u4e3a\u5e03\u5c14\u503c\u3002<\/p>\n<p>\u4e3a\u4e86\u8fdb\u4e00\u6b65\u7ec3\u4e60\uff0c\u8bf7\u5c1d\u8bd5\u4f7f\u7528\u975e\u5e03\u5c14\u8868\u8fbe\u5f0f\u5f15\u53d1\u9519\u8bef\u3002\u4e3a\u6b64\uff0c\u5c06\u4e00\u4e2a\u4e0d\u80fd\u8f6c\u6362\u4e3a\u5e03\u5c14\u503c\u7684\u6574\u6570\u53d8\u91cf\u653e\u7f6e\u5728\u6761\u4ef6\u62ec\u53f7\u4e2d\uff0c\u50cf\u8fd9\u6837\uff1a<\/p>\n<pre class=\"post-pre\"><code><ol>\r\n<li data-prefix=\"jshell&gt;\">int x <span class=\"token operator\">=<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/li>\r\n<li data-prefix=\"jshell&gt;\"><mark><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>x<span class=\"token punctuation\">)<\/span><\/mark> <span class=\"token punctuation\">{<\/span>\r\n<\/li>\r\n<li data-prefix=\"jshell&gt;\">    System.out.println<span class=\"token punctuation\">(<\/span><span class=\"token string\">\"Will this work?\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/li>\r\n<li data-prefix=\"jshell&gt;\"><span class=\"token punctuation\">}<\/span>\r\n<\/li>\r\n<\/ol>\r\n<\/code><\/pre>\n<p>\u5728\u7b2c\u4e00\u884c\uff0c\u4f60\u5b9a\u4e49\u4e86\u4e00\u4e2a\u6574\u6570\u53d8\u91cfx\uff0c\u5e76\u7ed9\u5b83\u8d4b\u4e86\u4e00\u4e2a\u503c\uff081\uff09\u3002\u7b2c\u4e8c\u884c\u662f\u6761\u4ef6<code>if (x)<\/code>\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\uff0c\u56e0\u4e3ax\u4e0d\u80fd\u8f6c\u6362\u4e3a\u5e03\u5c14\u503c\u3002\u5f53\u4f60\u5728jshell\u4e2d\u8fd0\u884c\u4ee5\u4e0a\u4ee3\u7801\u65f6\uff0c\u4f60\u5c06\u4f1a\u5f97\u5230\u4ee5\u4e0b\u9519\u8bef\uff1a<\/p>\n<pre class=\"post-pre\"><code><div class=\"secondary-code-label\" title=\"Output\">Outputx ==&gt; 1\r\n|  Error:\r\n|  incompatible types: int cannot be converted to boolean\r\n|  if (x) {\r\n|      ^\r\n<\/code><\/pre>\n<p>\u7b2c\u4e00\u884c\u786e\u8ba4x\u63a5\u6536\u5230\u503c1\u3002\u63a5\u4e0b\u6765\u7684\u51e0\u884c\u63cf\u8ff0\u4e86\u4e0d\u517c\u5bb9\u7c7b\u578b\u7684\u9519\u8bef\uff0c\u5e76\u89e3\u91ca\u4e86\u4e00\u4e2a\u6574\u6570\u503c\uff08\u5982x\uff09\u65e0\u6cd5\u8f6c\u6362\u4e3a\u5e03\u5c14\u503c\u3002\u6bcf\u5f53\u4f60\u9047\u5230\u8fd9\u6837\u7684\u9519\u8bef\uff0c\u4f60\u5c31\u9700\u8981\u4ed4\u7ec6\u68c0\u67e5\u4f60\u7684\u6bd4\u8f83\u3002<\/p>\n<p>\u50cf\u8fd9\u6837\u7684\u975e\u5e03\u5c14\u6761\u4ef6\u8bed\u53e5\u53ef\u80fd\u662f\u6761\u4ef6\u8bed\u53e5\u4e2d\u6700\u5e38\u89c1\u7684\u9677\u9631\u3002\u5e78\u8fd0\u7684\u662f\uff0c\u73b0\u4ee3\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u5728\u7f16\u5199\u65f6\u5c31\u80fd\u6355\u6349\u5230\u8fd9\u79cd\u9519\u8bef\u3002\u5373\u4f7f\u60a8\u6ca1\u6709\u4f7f\u7528IDE\uff0c\u9519\u8bef\u4ecd\u7136\u5f88\u5bb9\u6613\u53d1\u73b0\u3002<\/p>\n<h2>\u5728\u6ca1\u6709\u4ee3\u7801\u5757\u7684\u60c5\u51b5\u4e0b\u7f16\u5199\u6761\u4ef6 if \u8bed\u53e5<\/h2>\n<p>Java\u7684if\u6761\u4ef6\u8bed\u53e5\u7684\u4e00\u4e2a\u7279\u70b9\u662f\u53ef\u4ee5\u4ee5\u66f4\u77ed\u7684\u65b9\u5f0f\u4e66\u5199\uff0c\u800c\u4e0d\u9700\u8981\u4f7f\u7528\u4ee3\u7801\u5757\u3002\u867d\u7136\u4e0d\u5efa\u8bae\u5728\u4e0d\u4f7f\u7528\u4ee3\u7801\u5757\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u6761\u4ef6\u8bed\u53e5\uff0c\u4f46\u4f60\u5e94\u8be5\u4e86\u89e3\u5230\u8fd9\u79cd\u4e66\u5199\u65b9\u5f0f\u662f\u53ef\u884c\u7684\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u5982\u679c\u4f60\u5728\u5b66\u4e60Java\u8003\u8bd5\u6216\u53c2\u52a0\u5de5\u4f5c\u9762\u8bd5\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u7c7b\u4f3c\u7684\u4ee4\u4eba\u56f0\u60d1\u7684\u4f8b\u5b50\uff0c\u6240\u4ee5\u4f60\u5e94\u8be5\u505a\u597d\u51c6\u5907\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u4f60\u53ef\u4ee5\u4e0d\u7528\u4e00\u6574\u5757\u7684\u4ee3\u7801\uff0c\u800c\u662f\u5199\u4e00\u4e2a\u50cf\u8fd9\u6837\u7684\u8bed\u53e5\u3002<\/p>\n<pre class=\"post-pre\"><code><ol>\r\n<li data-prefix=\"1\"><span class=\"token keyword\">int<\/span> x <span class=\"token operator\">=<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/li>\r\n<li data-prefix=\"2\"><span class=\"token keyword\">int<\/span> y <span class=\"token operator\">=<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/li>\r\n<li data-prefix=\"3\"><mark><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">&gt;<\/span> y<span class=\"token punctuation\">)<\/span><\/mark>\r\n<\/li>\r\n<li data-prefix=\"4\">    <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">+<\/span> <span class=\"token string\">\" is bigger than \"<\/span> <span class=\"token operator\">+<\/span> y<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/li>\r\n<\/ol>\r\n<\/code><\/pre>\n<p>\u4e0e\u524d\u9762\u7684\u4f8b\u5b50\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\uff0c\u5728\u6761\u4ef6\u8bed\u53e5 <code>if (x &gt; y)<\/code> \u4e4b\u540e\u6ca1\u6709\u4ee3\u7801\u5757\u3002\u76f8\u53cd\uff0c\u5728\u6761\u4ef6\u8bed\u53e5 <code>if (x &gt; y)<\/code> \u4e4b\u540e\u7d27\u63a5\u7740\u7684\u5c31\u662f\u76ee\u6807\u8bed\u53e5 <code>System.out.println(x + \" is bigger than \" + y)<\/code>\u3002<\/p>\n<p>\u5f53\u4f60\u5728jshell\u4e2d\u8fd0\u884c\u6b64\u4ee3\u7801\u65f6\uff0c\u4f60\u5c06\u5f97\u5230\u4e0e\u5148\u524d\u793a\u4f8b\u76f8\u540c\u7684\u8f93\u51fa\u7ed3\u679c\u3002<\/p>\n<pre class=\"post-pre\"><code><div class=\"secondary-code-label\" title=\"Output\">Outputx ==&gt; 1\r\ny ==&gt; 0\r\n1 is bigger than 0\r\n<\/code><\/pre>\n<p>x\u548cy\u7684\u503c\u5c06\u6253\u5370\u5728\u524d\u4e24\u884c\u30021\u5927\u4e8e0\u7684\u786e\u8ba4\u6d88\u606f\u5c06\u5728\u7b2c\u4e09\u884c\u6253\u5370\u3002<\/p>\n<p>\u5f53\u6761\u4ef6\u8bed\u53e5\u540e\u6ca1\u6709\u4ee3\u7801\u5757\u65f6\uff0c\u53ea\u6709\u7d27\u63a5\u5728\u6761\u4ef6\u8bed\u53e5\u540e\u7684\u4e00\u884c\u4f9d\u8d56\u4e8e\u8be5\u6761\u4ef6\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u65e0\u8bba\u6761\u4ef6\u5982\u4f55\uff0c\u5728\u7b2c4\u884c\u4e4b\u540e\u7684\u4efb\u4f55\u8bed\u53e5\u90fd\u4f1a\u6267\u884c\u3002\u4f8b\u5982\uff0c\u5c1d\u8bd5\u5c06 x \u66f4\u6539\u4e3a 0\uff0c\u4f7f\u5176\u4e0d\u5927\u4e8e y\uff0c\u5e76\u6dfb\u52a0\u5982\u4e0b\u7684\u7b2c\u4e94\u884c\u4ee3\u7801\uff1a<\/p>\n<pre class=\"post-pre\"><code><ol>\r\n<li data-prefix=\"1\"><span class=\"token keyword\">int<\/span> x <span class=\"token operator\">=<\/span> <mark><span class=\"token number\">0<\/span><\/mark><span class=\"token punctuation\">;<\/span>\r\n<\/li>\r\n<li data-prefix=\"2\"><span class=\"token keyword\">int<\/span> y <span class=\"token operator\">=<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/li>\r\n<li data-prefix=\"3\"><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">&gt;<\/span> y<span class=\"token punctuation\">)<\/span>\r\n<\/li>\r\n<li data-prefix=\"4\">    <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">+<\/span> <span class=\"token string\">\" is bigger than \"<\/span> <span class=\"token operator\">+<\/span> y<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\r\n<\/li>\r\n<li data-prefix=\"5\">    <mark><span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"This line is always printed.\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/mark>\r\n<\/li>\r\n<\/ol>\r\n<\/code><\/pre>\n<p>\u5f53\u4f60\u5728jshell\u4e2d\u8fd0\u884c\u4e0a\u8ff0\u4ee3\u7801\u65f6\uff0c\u4f60\u5c06\u4f1a\u5f97\u5230\u4ee5\u4e0b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<pre class=\"post-pre\"><code><div class=\"secondary-code-label\" title=\"Output\">Outputx ==&gt; 0\r\ny ==&gt; 0\r\nThis line is always printed.\r\n<\/code><\/pre>\n<p>\u6b64\u5916\uff0c\u7b2c5\u884c\u7684\u7f29\u8fdb\u662f\u4e0d\u5fc5\u8981\u7684\u3002\u5b83\u53ea\u662f\u4e3a\u4e86\u6697\u793a\u7b2c5\u884c\u7684\u6267\u884c\u53d6\u51b3\u4e8e\u6761\u4ef6\uff0c\u800c\u5b9e\u9645\u60c5\u51b5\u5e76\u975e\u5982\u6b64\u3002\u53ef\u4ee5\u7701\u7565\u6b64\u7f29\u8fdb\uff0c\u4f46\u8fd9\u5e76\u4e0d\u4f1a\u4f7f\u4ee3\u7801\u66f4\u6e05\u6670\u3002<\/p>\n<p>\u4f7f\u7528\u6ca1\u6709\u4ee3\u7801\u5757\u7684\u6761\u4ef6\u8bed\u53e5\u65e2\u4e0d\u76f4\u89c2\u4e5f\u4e0d\u6613\u4e8e\u8ffd\u8e2a\uff0c\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u4f60\u5e94\u8be5\u8c28\u614e\u4f7f\u7528\u7b80\u5199\u8bed\u6cd5\u7684\u539f\u56e0\u3002\u4e3a\u4e86\u4fdd\u6301\u4ee3\u7801\u7684\u6574\u6d01\u548c\u53ef\u8bfb\u6027\uff0c\u6700\u597d\u4f7f\u7528\u4ee3\u7801\u5757\u8bed\u53e5\uff0c\u56e0\u4e3a\u5b83\u4eec\u66f4\u6613\u8bfb\uff0c\u5e76\u4e14\u5141\u8bb8\u4f60\u7f16\u5199\u591a\u884c\u6709\u6761\u4ef6\u6267\u884c\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u5d4c\u5957\u7684if\u8bed\u53e5\u662f\u4e00\u79cd\u53ef\u4ee5\u7f16\u5199\u4f46\u901a\u5e38\u4e0d\u63a8\u8350\u7684\u4ee3\u7801\u793a\u4f8b\u3002\u5728\u4e0b\u4e00\u8282\u4e2d\uff0c\u4f60\u5c06\u63a2\u7d22\u5d4c\u5957\u7684if\u8bed\u53e5\uff0c\u4ee5\u66f4\u597d\u5730\u7406\u89e3\u5b83\u4eec\u7684\u4ef7\u503c\u548c\u7f3a\u70b9\u3002<\/p>\n<h2>\u5d4c\u5957\u7684If\u8bed\u53e5<\/h2>\n<p>\u4e3a\u4e86\u521b\u5efa\u66f4\u590d\u6742\u7684\u6761\u4ef6\u7ed3\u6784\uff0c\u53ef\u4ee5\u5c06\u8bb8\u591aif\u8bed\u53e5\u7ec4\u5408\u8d77\u6765\u3002\u8981\u521b\u5efa\u5d4c\u5957\u7684if\u8bed\u53e5\uff0c\u53ef\u4ee5\u5c06\u53e6\u4e00\u4e2aif\u8bed\u53e5\u653e\u7f6e\u5728\u7236if\u8bed\u53e5\u5185\u90e8\u800c\u4e0d\u662f\u5728\u4ee3\u7801\u5757\u4e2d\u3002<\/p>\n<p>\u8fd9\u79cd\u505a\u6cd5\u901a\u5e38\u4e0d\u88ab\u63a8\u8350\uff0c\u56e0\u4e3a\u5b83\u4f1a\u4f7f\u4f60\u7684\u4ee3\u7801\u53d8\u5f97\u66f4\u96be\u9605\u8bfb\u548c\u7406\u89e3\u3002\u7136\u800c\uff0c\u5d4c\u5957\u7684if\u8bed\u53e5\u6709\u65f6\u786e\u5b9e\u5177\u6709\u5b9e\u9645\u7528\u9014\uff0c\u56e0\u6b64\u719f\u6089\u5b83\u4eec\u4f1a\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p>\u4e3a\u4e86\u7406\u89e3\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff0c\u4f60\u9700\u8981\u901a\u8fc7\u6dfb\u52a0\u4e00\u4e2aif\u8bed\u53e5\u6765\u6269\u5c55\u4e4b\u524d\u7684\u4f8b\u5b50\u3002\u4f60\u5c06\u518d\u6b21\u5c06y\u4e0e0\u8fdb\u884c\u6bd4\u8f83\u4ee5\u8bc4\u4f30\u5b83\u4eec\u662f\u5426\u76f8\u7b49\u3002\u8bf7\u5c06\u4ee5\u4e0b\u4ee3\u7801\u6dfb\u52a0\u5230JShell\u4e2d\u3002<\/p>\n<pre class=\"post-pre\"><code><ol><li data-prefix=\"1\"><span class=\"token keyword\">int<\/span> x <span class=\"token operator\">=<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"2\"><span class=\"token keyword\">int<\/span> y <span class=\"token operator\">=<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"3\"><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">&gt;<\/span> y<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><\/li><li data-prefix=\"4\">  <mark><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>y <span class=\"token operator\">==<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><\/mark> <span class=\"token punctuation\">{<\/span><\/li><li data-prefix=\"5\">    <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"This is legal but does not look clean.\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"6\">  <span class=\"token punctuation\">}<\/span><\/li><li data-prefix=\"7\"><span class=\"token punctuation\">}<\/span><\/li><\/ol><\/code><\/pre>\n<p>\u524d\u4e09\u884c\u4e0e\u4e4b\u524d\u7684\u793a\u4f8b\u4fdd\u6301\u4e0d\u53d8\uff1a\u5b9a\u4e49\u4e86\u4e24\u4e2a\u6574\u578b\u53d8\u91cf\uff08x\u548cy\uff09\u5e76\u8fdb\u884c\u6bd4\u8f83\u3002\u7b2c\u56db\u884c\uff0c\u53e6\u4e00\u4e2aif\u8bed\u53e5\u6bd4\u8f83y\u662f\u5426\u7b49\u4e8e0\u3002\u5982\u679c\u4e3a\u771f\uff0cJava\u5c06\u6267\u884c\u7b2c\u4e94\u884c\uff0c\u5176\u4e2d\u6709\u4e00\u4e2a\u5e26\u6709\u6d88\u606f\u201c\u8fd9\u662f\u5408\u6cd5\u7684\uff0c\u4f46\u4e0d\u591f\u7b80\u6d01\u201d\u7684<code>println()<\/code>\u8bed\u53e5\u3002<\/p>\n<p>\u5f53\u4f60\u5728JShell\u4e2d\u8fd0\u884c\u6b64\u547d\u4ee4\u65f6\uff0c\u4f60\u5c06\u5f97\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<pre class=\"post-pre\"><code><div class=\"secondary-code-label\" title=\"Output\">Output<\/div>x ==&gt; 1\r\ny ==&gt; 0\r\nThis is legal but does not look clean.\r\n<\/code><\/pre>\n<p>\u524d\u4e24\u884c\u786e\u8ba4\u4e86x\u548cy\u7684\u503c\u3002\u7b2c\u4e09\u884c\u663e\u793a\uff1a\u201c\u8fd9\u662f\u5408\u6cd5\u7684\uff0c\u4f46\u770b\u8d77\u6765\u4e0d\u5e72\u51c0\u3002\u201d\u8be5\u6d88\u606f\u786e\u8ba4\u4ee3\u7801\u5757\u5df2\u7ecf\u6267\u884c\uff0c\u56e0\u4e3aif\u6761\u4ef6\u90fd\u6ee1\u8db3\uff1ax > y\u548cy == 0\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u65e0\u9650\u5d4c\u5957if\u8bed\u53e5\u3002\u7136\u800c\uff0c\u6bcf\u4e2a\u5d4c\u5957\u7684if\u8bed\u53e5\u90fd\u4f1a\u589e\u52a0\u4ee3\u7801\u7684\u590d\u6742\u6027\uff0c\u964d\u4f4e\u5176\u53ef\u8bfb\u6027\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u5d4c\u5957if\u8bed\u53e5\u901a\u5e38\u4e0d\u88ab\u8ba4\u4e3a\u662f\u826f\u597d\u7684\u7f16\u7a0b\u5b9e\u8df5\u3002<\/p>\n<p>\u7136\u800c\uff0c\u5d4c\u5957\u7684\u6761\u4ef6\u7ed3\u6784\u786e\u5b9e\u5177\u6709\u4e00\u4e9b\u5b9e\u9645\u5e94\u7528\u3002\u6709\u65f6\uff0c\u4e3a\u4e86\u7f16\u5199\u66f4\u77ed\u7684\u4ee3\u7801\u5e76\u8282\u7701\u65f6\u95f4\uff0c\u727a\u7272\u53ef\u8bfb\u6027\u5e76\u589e\u52a0\u590d\u6742\u6027\u53ef\u80fd\u662f\u503c\u5f97\u7684\u3002\u56e0\u6b64\uff0c\u5728\u8003\u8bd5\u3001\u9762\u8bd5\u6216\u5b9e\u9645\u751f\u4ea7\u4ee3\u7801\u4e2d\uff0c\u60a8\u53ef\u80fd\u4f1a\u9047\u5230\u5d4c\u5957\u8bed\u53e5\u3002<\/p>\n<h2>\u4f7f\u7528\u6269\u5c55\u7684\u6761\u4ef6\u8bed\u53e5\u4e0eElse If\u548cElse\u8bed\u53e5<\/h2>\n<p>\u5982\u679c\u4f7f\u7528<code>else if<\/code>\u548c<code>else<\/code>\u8865\u5145\u8bed\u53e5\uff0c\u6761\u4ef6\u8bed\u53e5\u53ef\u4ee5\u8fdb\u4e00\u6b65\u6269\u5c55\u4ee5\u5904\u7406\u989d\u5916\u7684\u5339\u914d\u6807\u51c6\u3002<code>else<\/code>\u8bed\u53e5\u53ea\u80fd\u5728\u521d\u59cb<code>if<\/code>\u8bed\u53e5\u4e4b\u540e\u4f7f\u7528\u3002\u4f7f\u7528<code>else if<\/code>\uff0c\u4f60\u53ef\u4ee5\u6dfb\u52a0\u65e0\u9650\u591a\u4e2a\u989d\u5916\u7684\u6761\u4ef6\u8bed\u53e5\uff0c\u7c7b\u4f3c\u4e8e\u7b2c\u4e00\u4e2a<code>if<\/code>\u3002\u4f7f\u7528\u6700\u540e\u7684\u53ef\u9009<code>else<\/code>\uff0c\u4f60\u53ef\u4ee5\u6307\u5b9a\u5728\u6ca1\u6709\u4e4b\u524d\u7684\u6761\u4ef6\u8bed\u53e5\u5339\u914d\u65f6\u7a0b\u5e8f\u6d41\u5e94\u8be5\u9075\u5faa\u7684\u9ed8\u8ba4\u8def\u5f84\u3002<\/p>\n<p>\u901a\u8fc7\u4f7f\u7528<code>else if<\/code>\u548c<code>else<\/code>\uff0c\u4f60\u53ef\u4ee5\u5c06\u7a0b\u5e8f\u6d41\u5206\u652f\u5230\u6bd4\u5355\u4e2a<code>if<\/code>\u66f4\u591a\u7684\u65b9\u5411\u3002\u56e0\u6b64\uff0c\u4f60\u53ef\u4ee5\u6784\u5efa\u65e0\u6cd5\u4ee5\u5176\u4ed6\u65b9\u5f0f\u6784\u5efa\u7684\u590d\u6742\u6761\u4ef6\u7ed3\u6784\u3002\u5728\u4e0d\u540c\u7684\u65b9\u5411\u4e0a\u5206\u652f\u4ee3\u7801\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5904\u7406\u66f4\u590d\u6742\u7684\u4e1a\u52a1\u60c5\u51b5\u3002\u7136\u800c\uff0c\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u4e1a\u52a1\u9700\u6c42\u4f17\u591a\uff0c\u5e76\u4e14\u8bbe\u8ba1\u6d41\u7a0b\u4e0d\u4e00\u5b9a\u662f\u76f4\u63a5\u7684\u3002<\/p>\n<p>\u4f7f\u7528\u4e0b\u9762\u7684\u4ee3\u7801\u793a\u4f8b\u6765\u4e86\u89e3<code>else if<\/code>\u548c<code>else<\/code>\u8bed\u53e5\u7684\u6982\u5ff5\u3002\u4f60\u5c06\u6269\u5c55\u4e4b\u524d\u4f7f\u7528\u7684\u4ee3\u7801\u5e76\u6dfb\u52a0\u66f4\u591a\u7684\u6761\u4ef6\u5206\u652f\u3002\u8fd9\u4e9b\u65b0\u7684\u6761\u4ef6\u5c06\u7ee7\u7eed\u6bd4\u8f83x\u548cy\u3002<\/p>\n<p>\u8fd9\u662f\u6587\u7ae0\u300a\u5982\u4f55\u5728Java\u4e2d\u7f16\u5199\u6761\u4ef6\u8bed\u53e5\u300b\u7684\u7b2c4\u90e8\u5206\uff08\u51715\u90e8\u5206\uff09\u3002<\/p>\n<pre class=\"post-pre\"><code><ol>\r\n<li data-prefix=\"1\"><span class=\"token keyword\">int<\/span> x <span class=\"token operator\">=<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><\/li>\r\n<li data-prefix=\"2\"><span class=\"token keyword\">int<\/span> y <span class=\"token operator\">=<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><\/li>\r\n<li data-prefix=\"3\"><span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">><\/span> y<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><\/li>\r\n<li data-prefix=\"4\">    <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">+<\/span> <span class=\"token string\">\" is bigger than \"<\/span> <span class=\"token operator\">+<\/span> y<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li>\r\n<li data-prefix=\"5\"><span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">&lt;<\/span> y<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><\/li>\r\n<li data-prefix=\"6\">    <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span>y <span class=\"token operator\">+<\/span> <span class=\"token string\">\" is bigger than \"<\/span> <span class=\"token operator\">+<\/span> x<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li>\r\n<li data-prefix=\"7\"><span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">==<\/span> y<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><\/li>\r\n<li data-prefix=\"8\">    <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">+<\/span> <span class=\"token string\">\" is equal to \"<\/span> <span class=\"token operator\">+<\/span> y<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li>\r\n<li data-prefix=\"9\"><span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">else<\/span> <span class=\"token punctuation\">{<\/span><\/li>\r\n<li data-prefix=\"10\">    <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span>x <span class=\"token operator\">+<\/span> <span class=\"token string\">\" cannot be compared to \"<\/span> <span class=\"token operator\">+<\/span> y<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li>\r\n<li data-prefix=\"11\"><span class=\"token punctuation\">}<\/span><\/li>\r\n<\/ol>\r\n<\/code><\/pre>\n<p>\u6839\u636e\u4e0a\u8ff0\u4ee3\u7801\uff0c\u7b2c1\u884c\u548c\u7b2c2\u884c\u5b9a\u4e49\u4e86\u4e24\u4e2a\u53d8\u91cf<code>x<\/code>\u548c<code>y<\/code>\uff0c\u5b83\u4eec\u7684\u503c\u5206\u522b\u4e3a1\u548c0\u3002\u5728\u7b2c3\u884c\u548c\u7b2c4\u884c\u4e2d\uff0c\u4f7f\u7528<code>if<\/code>\u8bed\u53e5\u8bc4\u4f30<code>x<\/code>\u662f\u5426\u5927\u4e8e<code>y<\/code>\u3002\u5982\u679c\u8bc4\u4f30\u7ed3\u679c\u4e3a\u771f\uff0c\u5219\u6253\u5370\u6587\u672c\u201cx\u5927\u4e8ey\u201d\u5e76\u9000\u51fa\u6761\u4ef6\u7ed3\u6784\u3002\u5982\u679c\u8bc4\u4f30\u7ed3\u679c\u4e3a\u5047\uff0c\u5219\u7a0b\u5e8f\u5c06\u7ee7\u7eed\u6267\u884c\u4e0b\u4e00\u4e2a\u6761\u4ef6\u3002\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u4ee3\u7801\u4e0e\u4e4b\u524d\u7684\u793a\u4f8b\u76f8\u540c\u3002<\/p>\n<p>\u5728\u7b2c5\u884c\uff0c\u5728<code>if<\/code>\u8bed\u53e5\u7684\u95ed\u5408\u62ec\u53f7\u4e4b\u540e\uff0c\u7d27\u8ddf\u7740\u4e00\u4e2a<code>else if<\/code>\u8bed\u53e5\u3002\u5b83\u5177\u6709\u7c7b\u4f3c\u4e8e<code>if<\/code>\u8bed\u53e5\u7684\u8bed\u6cd5\uff1a\u62ec\u53f7\u5185\u6709\u4e00\u4e2a\u5e03\u5c14\u8868\u8fbe\u5f0f\uff0c\u5e76\u4e14\u540e\u9762\u8ddf\u6709\u4e00\u6bb5\u4ee3\u7801\u5757\u3002\u8be5\u8868\u8fbe\u5f0f\u8bc4\u4f30<code>y<\/code>\u662f\u5426\u5927\u4e8e<code>x<\/code>\uff0c\u4e0e\u4e0a\u4e00\u4e2a<code>if<\/code>\u8bed\u53e5\u76f8\u53cd\u3002\u5982\u679c\u8868\u8fbe\u5f0f\u4e3a\u771f\uff0c\u5219\u5c06\u6267\u884c\u5176\u540e\u7684\u4ee3\u7801\u5757\uff0c\u518d\u6b21\u9000\u51fa\u6761\u4ef6\u7ed3\u6784\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8fd9\u662f\u7b2c6\u884c\u7684\u8bed\u53e5\uff0c\u5c06\u6253\u5370\u51fa\u201cy\u5927\u4e8ex\u201d\u3002<\/p>\n<p>\u5728\u7b2c7\u884c\u662f\u53e6\u4e00\u4e2a<code>else if<\/code>\u6761\u4ef6\u8bed\u53e5\u3002\u8fd9\u6b21\uff0c\u60a8\u5728\u62ec\u53f7\u4e2d\u68c0\u67e5<code>x<\/code>\u662f\u5426\u7b49\u4e8e<code>y<\/code>\u3002\u5982\u679c\u4e3a\u771f\uff0c\u5219\u5c06\u6267\u884c\u7b2c8\u884c\u7684\u8bed\u53e5\uff0c\u5e76\u6253\u5370\u201cx\u7b49\u4e8ey\u201d\u3002\u6b64\u7c7b<code>else if<\/code>\u8bed\u53e5\u53ef\u4ee5\u65e0\u9650\u6dfb\u52a0\uff0c\u4e00\u4e2a\u63a5\u4e00\u4e2a\u5730\u8bc4\u4f30\u4e0d\u540c\u7684\u6761\u4ef6\u3002<\/p>\n<p>\u5728\u7b2c9\u884c\u51fa\u73b0\u4e86\u6700\u7ec8\u7684<code>else<\/code>\u8bed\u53e5\u3002\u5b83\u59cb\u7ec8\u662f\u6700\u540e\u4e00\u4e2a\uff0c\u4e14\u6ca1\u6709\u6761\u4ef6\uff0c\u8fd9\u610f\u5473\u7740\u5982\u679c\u4e4b\u524d\u6ca1\u6709\u5339\u914d\u7684\u6761\u4ef6\u8bed\u53e5\uff0c\u5176\u5206\u652f\u603b\u662f\u4f1a\u6267\u884c\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5728\u6ca1\u6709\u6ee1\u8db3<code>if<\/code>\u6216<code>else if<\/code>\u6761\u4ef6\u7684\u60c5\u51b5\u4e0b\uff0c\u4f1a\u6267\u884c<code>else<\/code>\u540e\u9762\u7684\u4ee3\u7801\u5757\u3002\u5982\u679c\u8fd9\u662f\u771f\u7684\uff0c\u90a3\u4e48\u7b2c10\u884c\u4e0a\u7684\u4ee3\u7801\u5c06\u4f1a\u6267\u884c\uff0c\u5e76\u6253\u5370\u51fa\u201cx\u4e0d\u80fd\u4e0ey\u8fdb\u884c\u6bd4\u8f83\u201d\u3002<\/p>\n<p>\u5728\u8fd9\u79cd\u590d\u6742\u7684\u6761\u4ef6\u7ed3\u6784\u4e2d\uff0c\u53ea\u9700\u8981\u7b2c\u4e00\u4e2a<code>if<\/code>\u8bed\u53e5\u3002\u5982\u679c\u4f60\u60f3\u8981\u8fdb\u884c\u989d\u5916\u7684\u6bd4\u8f83\uff0c\u53ef\u4ee5\u4f7f\u7528\u96f6\u4e2a\u6216\u591a\u4e2a<code>else if<\/code>\u8bed\u53e5\u3002\u6700\u540e\uff0c\u4f60\u53ef\u4ee5\u52a0\u4e0a\u4e00\u4e2a\u53ef\u9009\u7684<code>else<\/code>\u8bed\u53e5\uff0c\u4ee5\u5339\u914d\u5176\u4ed6\u6761\u4ef6\u90fd\u4e0d\u6ee1\u8db3\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u5f53\u60a8\u5728jshell\u4e2d\u8fd0\u884c\u4e0a\u8ff0\u4ee3\u7801\u65f6\uff0c\u60a8\u5c06\u83b7\u5f97\u4ee5\u4e0b\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<pre class=\"post-pre\"><code><div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\r\nx ==&gt; 1\r\ny ==&gt; 0\r\n1 is bigger than 0\r\n<\/code><\/pre>\n<p>\u4ece\u4e0a\u9762\u7684\u8f93\u51fa\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u7b2c\u4e00\u884c\u548c\u7b2c\u4e8c\u884c\u786e\u8ba4\u4e86<code>x<\/code>\u548c<code>y<\/code>\u7684\u503c\u5206\u522b\u4e3a1\u548c0\u3002\u7b2c\u4e09\u884c\u8f93\u51fa\u201c1\u5927\u4e8e0\u201d\uff0c\u8bc1\u5b9e\u4e86\u5e03\u5c14\u8868\u8fbe\u5f0f\uff08<code>x > y<\/code>\uff09\u8fd4\u56de\u4e86<code>true<\/code>\uff0c\u5e76\u4e14\u5728\u5176\u540e\u7684\u4ee3\u7801\u5757\u5df2\u7ecf\u88ab\u6267\u884c\u3002<\/p>\n<p>\u7f16\u5199<code>if<\/code>\u3001<code>else if<\/code>\u548c<code>else<\/code>\u8bed\u53e5\u662f\u7f16\u5199\u590d\u6742\u6761\u4ef6\u7ed3\u6784\u7684\u597d\u65b9\u6cd5\uff0c\u56e0\u4e3a\u60a8\u53ef\u4ee5\u5728\u6bcf\u4e2a<code>if<\/code>\u548c<code>else if<\/code>\u8bed\u53e5\u4e2d\u653e\u7f6e\u4e0d\u540c\u7684\u6761\u4ef6\u3002\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u60a8\u9996\u5148\u6bd4\u8f83\u4e86<code>x > y<\/code>\uff0c\u7136\u540e\u662f\u76f8\u53cd\u6761\u4ef6<code>x < y<\/code>\uff0c\u6700\u540e\u662f<code>x == y<\/code>\u3002\u5373\u4f7f\u5728\u53ea\u8fdb\u884c\u4e86\u5c11\u6570\u6bd4\u8f83\u7684\u60c5\u51b5\u4e0b\uff0c\u4ee3\u7801\u4ecd\u7136\u6613\u8bfb\u4e14\u6613\u4e8e\u7ba1\u7406\u3002<\/p>\n<p>\u7136\u800c\uff0c\u5982\u679c\u4f60\u9700\u8981\u8fdb\u884c\u66f4\u591a\u7684\u6bd4\u8f83\uff0c\u6dfb\u52a0\u66f4\u591a\u7684<code>else if<\/code>\u8bed\u53e5\u4f1a\u4f7f\u4ee3\u7801\u96be\u4ee5\u7406\u89e3\u751a\u81f3\u4ee4\u4eba\u56f0\u60d1\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u5728\u53ef\u80fd\u7684\u60c5\u51b5\u4e0b\u5e94\u8be5\u4f7f\u4f60\u7684\u7ed3\u6784\u5c0f\u800c\u7b80\u5355\u7684\u539f\u56e0\u3002\u6b64\u5916\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f7f\u7528<code>switch<\/code>\u8bed\u53e5\u53ef\u4ee5\u66ff\u4ee3\u8fd9\u79cd\u590d\u6742\u7684\u7ed3\u6784\uff0c\u4f60\u5c06\u5728\u4e0b\u4e00\u90e8\u5206\u4e2d\u4f7f\u7528\u5b83\u3002<\/p>\n<h2>\u4f7f\u7528<code>switch<\/code>\u6761\u4ef6<\/h2>\n<p><code>switch<\/code>\u8bed\u53e5\u662f\u53e6\u4e00\u79cd\u53ef\u7528\u4e8e\u6784\u5efa\u51b3\u7b56\u7ed3\u6784\u7684\u6761\u4ef6\u8bed\u53e5\u3002\u5b83\u4e0e<code>if<\/code>\u8bed\u53e5\u7c7b\u4f3c\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u7528\u4e8e\u6709\u6761\u4ef6\u5730\u63a7\u5236\u7a0b\u5e8f\u6d41\u7a0b\u3002\u7136\u800c\uff0c<code>switch<\/code>\u8bed\u53e5\u53ea\u9002\u7528\u4e8e\u5355\u4e00\u53d8\u91cf\uff0c\u5e76\u5c06\u5176\u4e0e\u4e0d\u540c\u7684\u9884\u5b9a\u4e49\u60c5\u51b5\u8fdb\u884c\u5339\u914d\u3002\u56e0\u6b64\uff0c\u60a8\u4e0d\u80fd\u8bc4\u4f30\u8bf8\u5982 <code>x > y<\/code> \u8fd9\u6837\u7684\u5e03\u5c14\u8868\u8fbe\u5f0f\u3002\u76f8\u53cd\uff0c\u60a8\u53ef\u4ee5\u6709\u4e00\u4e2a<code>int<\/code>\u53d8\u91cf\uff0c\u5e76\u5c06\u5176\u503c\u4e0e\u5176\u4ed6<code>int<\/code>\u53d8\u91cf\u8fdb\u884c\u5339\u914d\uff1b\u5f53\u5339\u914d\u6210\u529f\uff08\u5373<code>case<\/code>\u60c5\u51b5\uff09\uff0c\u7a0b\u5e8f\u6d41\u7a0b\u5c06\u6839\u636e\u5339\u914d\u7ed3\u679c\u8fdb\u884c\u91cd\u5b9a\u5411\u3002<\/p>\n<p><code>switch<\/code>\u6761\u4ef6\u8bed\u53e5\u6709\u4e24\u4e2a\u91cd\u8981\u7684\u89c4\u5219\u3002\u7b2c\u4e00\u4e2a\u89c4\u5219\u662f\u6bd4\u8f83\u7684\u53d8\u91cf\u53ea\u80fd\u662f\u7279\u5b9a\u7684\u6570\u636e\u7c7b\u578b\uff0c\u6bd4\u5982\u539f\u59cb\u7c7b\u578b<code>int<\/code>\u548c<code>char<\/code>\uff0c\u4ee5\u53ca\u5f15\u7528\u7c7b\u578b<code>String<\/code>\u548c<code>Integer<\/code>\u3002\uff08\u652f\u6301\u7684\u6570\u636e\u7c7b\u578b\u5b8c\u6574\u5217\u8868\u53ef\u4ee5\u5728\u5b98\u65b9<code>switch<\/code>\u6587\u6863\u4e2d\u627e\u5230\u3002\uff09\u56e0\u6b64\uff0c\u4f60\u4e0d\u80fd\u4f7f\u7528\u5e03\u5c14\u53d8\u91cf\uff0c\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48<code>switch<\/code>\u6761\u4ef6\u8bed\u53e5\u4e0d\u80fd\u5b8c\u5168\u66ff\u4ee3<code>if<\/code>\u6761\u4ef6\u8bed\u53e5\u7684\u539f\u56e0\u3002<\/p>\n<p>\u53e6\u4e00\u4e2a\u91cd\u8981\u7684\u89c4\u5219\u662f<code>case<\/code>\u8bed\u53e5\u7684\u503c\u5fc5\u987b\u662f\u5b57\u9762\u5e38\u91cf\u6216\u5e38\u91cf\u3002\u5e38\u91cf\u7c7b\u4f3c\u4e8e\u53d8\u91cf\uff0c\u4f46\u5728\u5b9a\u4e49\u65f6\u524d\u9762\u52a0\u4e0a\u5173\u952e\u8bcd<code>final<\/code>\u3002\u4e0e\u53d8\u91cf\u76f8\u6bd4\uff0c\u4e00\u65e6\u5e38\u91cf\u88ab\u5b9a\u4e49\uff0c\u5176\u503c\u4e0d\u80fd\u6539\u53d8\u3002\u6211\u4eec\u7684Java\u7cfb\u5217\u6559\u7a0b\u5c06\u5728\u672a\u6765\u8be6\u7ec6\u4ecb\u7ecd\u5e38\u91cf\u3002<\/p>\n<p><code>switch<\/code>\u7ed3\u6784\u6bd4<code>if<\/code>\u7ed3\u6784\u66f4\u52a0\u6709\u9650\uff0c\u5b83\u5e76\u4e0d\u5b8c\u5168\u66ff\u4ee3<code>if<\/code>\u7ed3\u6784\u3002\u7136\u800c\uff0c<code>switch<\/code>\u7ed3\u6784\u5177\u6709\u66f4\u9ad8\u7684\u53ef\u8bfb\u6027\uff0c\u5e76\u4e14\u5728\u53ef\u884c\u7684\u60c5\u51b5\u4e0b\u9002\u7528\u4e8e\u66f4\u591a\u7684\u6bd4\u8f83\uff0c\u8fd9\u662f\u5b83\u72ec\u7279\u7684\u4f18\u52bf\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u8bbe\u60f3\u60a8\u60f3\u5c06\u6bcf\u4e2a\u6708\u4efd\uff081\u523012\uff09\u7684\u6570\u5b57\u8868\u793a\u4e0e\u5bf9\u5e94\u7684\u6708\u4efd\u540d\u79f0\u8fdb\u884c\u5339\u914d\u3002\u4f7f\u7528<code>if-else if<\/code>\u7ed3\u6784\uff0c\u60a8\u9700\u8981\u8fdb\u884c\u5341\u4e8c\u4e2a\u7c7b\u4f3c\u7684\u6bd4\u8f83\u3002\u4f46\u662f\uff0c\u4f7f\u7528<code>switch<\/code>\u8bed\u53e5\uff0c\u60a8\u53ef\u4ee5\u66f4\u7b80\u6d01\u5730\u5b8c\u6210\u8fd9\u9879\u4efb\u52a1\uff0c\u907f\u514d\u4e86\u91cd\u590d\u7684\u4ee3\u7801\u3002<\/p>\n<p>\u4e3a\u4e86\u7ec3\u4e60\u4f7f\u7528\u5e26\u6709\u6708\u4efd\u793a\u4f8b\u7684<code>switch<\/code>\u6761\u4ef6\u8bed\u6cd5\uff0c\u8bf7\u5c06\u4ee5\u4e0b\u4ee3\u7801\u6dfb\u52a0\u5230JShell\u4e2d\u3002\u8fd9\u91cc\u6709\u4e00\u4e2a\u6574\u6570\u53d8\u91cf\u8868\u793a\u4e00\u5e74\u4e2d\u7684\u6708\u4efd\uff0c\u6bcf\u4e2a\u6708\u4efd\u90fd\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684<code>case<\/code>\uff1a<\/p>\n<pre class=\"post-pre\"><code><ol><li data-prefix=\"1\"><span class=\"token keyword\">int<\/span> monthOfYear <span class=\"token operator\">=<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"2\"><mark><span class=\"token keyword\">switch<\/span> <span class=\"token punctuation\">(<\/span>monthOfYear<span class=\"token punctuation\">)<\/span><\/mark> <span class=\"token punctuation\">{<\/span><\/li><li data-prefix=\"3\"><mark><span class=\"token keyword\">case<\/span> <span class=\"token number\">1<\/span><\/mark><span class=\"token operator\">:<\/span><\/li><li data-prefix=\"4\">    <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"\u4e00\u6708\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"5\">    <mark><span class=\"token keyword\">break<\/span><\/mark><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"6\"><mark><span class=\"token keyword\">case<\/span> <span class=\"token number\">2<\/span><\/mark><span class=\"token operator\">:<\/span><\/li><li data-prefix=\"7\">    <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"\u4e8c\u6708\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"8\">    <mark><span class=\"token keyword\">break<\/span><\/mark><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"9\"><mark><span class=\"token keyword\">default<\/span><\/mark><span class=\"token operator\">:<\/span><\/li><li data-prefix=\"10\">    <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\"\u4e0d\u662f\u4e00\u4e2a\u6708\u4efd\"<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/li><li data-prefix=\"11\"><span class=\"token punctuation\">}<\/span><\/li><\/ol><\/code><\/pre>\n<p>\u7b2c\u4e00\u884c\u4e2d\uff0c\u6709\u4e00\u4e2a\u503c\u4e3a1\u7684\u53d8\u91cf<code>monthOfYear<\/code>\u3002\u8fd9\u4e2a\u53d8\u91cf\u5c06\u7528\u4e8e<code>switch<\/code>\u8bed\u53e5\u3002\u7b2c\u4e8c\u884c\u662f<code>switch<\/code>\u8bed\u53e5\u7684\u5b9a\u4e49\u3002\u53d8\u91cf<code>monthOfYear<\/code>\u88ab\u653e\u5728\u62ec\u53f7\u5185\uff0c\u8868\u793a\u5c06\u8fdb\u884c\u6bd4\u8f83\u3002\u4e4b\u540e\u5f00\u59cb\u4e86\u4e00\u4e2a\u4ee3\u7801\u5757\uff0c\u5728\u5176\u4e2d\u63cf\u8ff0\u4e86\u4e0d\u540c\u7684<code>case<\/code>\u6761\u4ef6\u3002<\/p>\n<p>\u5728\u7b2c3\u884c\u51fa\u73b0\u4e86\u7b2c\u4e00\u4e2a\u503c\u4e3a1\u7684\u60c5\u51b5\u3002\u7b2c\u4e00\u4e2a\u6bd4\u8f83\u5c06\u662f\u6708\u4efd\u662f\u5426\u7b49\u4e8e1\u3002\u4e00\u4e2a\u5192\u53f7\uff08<code>:<\/code>\uff09\u603b\u662f\u8ddf\u968f\u6bd4\u8f83\u7684\u503c\u3002\u5728\u7b2c4\u884c\u51fa\u73b0\u4e86<code>println()<\/code>\u65b9\u6cd5\uff0c\u7528\u4e8e\u6253\u5370\u51fa\u5982\u679c\u5339\u914d\u5230\u4e861\uff0c\u5e94\u8be5\u6253\u5370\u51fa\u201c\u4e00\u6708\u201d\u4f5c\u4e3a\u6708\u4efd\u7684\u540d\u79f0\u3002\u8fd9\u4e00\u884c\u53ef\u4ee5\u662f\u96f6\u4e2a\u6216\u591a\u4e2a\u8bed\u53e5\uff0c\u4e5f\u53ef\u4ee5\u662f\u96f6\u884c\u6216\u591a\u884c\u2014\u2014\u5373\u53ef\u4ee5\u8df3\u8fc7\u3002<\/p>\n<p>\u5728\u7b2c\u4e00\u4e2a<code>case<\/code>\u4e4b\u540e\uff0c\u7b2c5\u884c\u6709\u4e00\u4e2a<code>break<\/code>\u8bed\u53e5\uff0c\u5b83\u5728\u6761\u4ef6\u6ee1\u8db3\u65f6\u4f7f\u5f97<code>switch<\/code>\u6761\u4ef6\u7ed3\u6784\u88ab\u9000\u51fa\u3002\u56e0\u6b64\uff0c\u4e00\u65e6<code>break<\/code>\u88ab\u6267\u884c\uff0c\u5c31\u4e0d\u4f1a\u518d\u8bc4\u4f30\u5176\u4ed6<code>case<\/code>\u6761\u4ef6\u3002\u76f8\u53cd\uff0c\u7a0b\u5e8f\u6d41\u4f1a\u7ee7\u7eed\u5728<code>switch<\/code>\u6761\u4ef6\u7684\u95ed\u62ec\u53f7\u4e4b\u540e\u7ee7\u7eed\u8fdb\u884c\uff0c\u8fd9\u5728\u672c\u4f8b\u4e2d\u662f\u5728\u7b2c11\u884c\u3002\u8bf7\u6ce8\u610f\uff0c<code>break<\/code>\u662f\u53ef\u9009\u7684\uff0c\u60a8\u53ef\u80fd\u4f1a\u5fd8\u8bb0\u5305\u542b\u5b83\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c<code>switch<\/code>\u5c06\u7ee7\u7eed\u8bc4\u4f30\u5269\u4f59\u7684<code>case<\/code>\uff0c\u800c\u4e0d\u662f\u5728\u5339\u914d\u65f6\u8df3\u51fa\u6761\u4ef6\u7ed3\u6784\u3002\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u610f\u5916\u7684\u8f93\u51fa\u548c\u96be\u4ee5\u8c03\u8bd5\u7684\u95ee\u9898\u3002<\/p>\n<p>\u4e0b\u4e00\u4e2a<code>case<\/code>\u6761\u4ef6\u4f4d\u4e8e\u7b2c6\u30017\u548c8\u884c\uff0c\u5c06\u5339\u914d<code>monthOfYear<\/code>\u503c\u662f\u5426\u4e3a2\u3002\u8fd9\u4e09\u884c\u4e0e\u524d\u4e09\u884c\u5177\u6709\u76f8\u540c\u7684\u8bed\u6cd5\uff0c\u4f46\u5728\u7b2c7\u884c\u6709\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\u201c\u4e8c\u6708\u201d\u3002\u4e3a\u4e86\u7b80\u6d01\u8d77\u89c1\uff0c\u5176\u4f59\u5341\u4e2a\u6708\u4efd\u7684<code>case<\/code>\u6761\u4ef6\u7701\u7565\u4e86\u3002\u5426\u5219\uff0c\u5b83\u4eec\u4e5f\u4f1a\u6309\u7167\u8fd9\u4e2a\u7ed3\u6784\uff0c\u6bcf\u4e2a\u547d\u540d\u6708\u4efd\u90fd\u6709\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u5728\u7b2c9\u884c\u662f\u4e00\u4e2a<code>default<\/code>\u8bed\u53e5\u3002\u5b83\u6ca1\u6709\u6761\u4ef6\uff0c\u56e0\u6b64\u603b\u662f\u5339\u914d\u7684\u3002\u5b83\u662f\u53ef\u9009\u7684\uff0c\u5e76\u4e14\u7528\u4e8e\u5728\u6ca1\u6709\u4e4b\u524d\u5217\u51fa\u7684\u60c5\u51b5\u5339\u914d\u65f6\u5b9a\u4e49\u7a0b\u5e8f\u6d41\u7684\u9ed8\u8ba4\u8def\u5f84\u3002\u5b83\u7c7b\u4f3c\u4e8e<code>if<\/code>\u6761\u4ef6\u8bed\u53e5\u4e2d\u7684<code>else<\/code>\u8bed\u53e5\u3002<\/p>\n<p>\u5728\u7b2c11\u884c\uff0c\u6709\u4e00\u4e2a\u95ed\u62ec\u53f7\u7528\u4e8e\u7ec8\u6b62\u6761\u4ef6\u8bed\u53e5\u7684\u4ee3\u7801\u5757\u3002<\/p>\n<p>\u8981\u6267\u884c\u4e0a\u8ff0\u4ee3\u7801\uff0c\u8bf7\u5c06\u5176\u7c98\u8d34\u5230JShell\u4e2d\u3002\u60a8\u5c06\u6536\u5230\u4ee5\u4e0b\u8f93\u51fa\uff1a<\/p>\n<pre class=\"post-pre\"><code><div class=\"secondary-code-label\" title=\"Output\">\u8f93\u51fa<\/div>monthOfYear ==&gt; 1\r\n\u4e00\u6708\r\n<\/code><\/pre>\n<p>\u7b2c\u4e00\u884c\u786e\u8ba4\u4e86<code>monthOfYear<\/code>\u7684\u503c\u662f1\u3002\u7b2c\u4e8c\u884c\u6253\u5370\u51fa\u4e86\u201c\u4e00\u6708\u201d\uff0c\u8fd9\u610f\u5473\u7740\u503c\u4e3a1\u7684\u6761\u4ef6\u5df2\u7ecf\u5339\u914d\uff1a<code>monthOfYear<\/code>\u662f1\uff0c\u89e6\u53d1\u4e86\u4e0b\u4e00\u884c\u7684\u8bed\u53e5\u53bb\u6253\u5370\u201c\u4e00\u6708\u201d\u3002<\/p>\n<p>\u4f5c\u4e3a\u4e00\u9879\u7ec3\u4e60\uff0c\u5c1d\u8bd5\u6539\u53d8<code>monthOfYear<\/code>\u7684\u503c\uff0c\u589e\u52a0\u66f4\u591a\u7684\u6761\u4ef6\u8bed\u53e5\uff0c\u751a\u81f3\u5220\u9664<code>break<\/code>\u8bed\u53e5\uff0c\u4ee5\u7406\u89e3\u7ed3\u679c\u5c06\u5982\u4f55\u6539\u53d8\u3002<\/p>\n<h2>\u7ed3\u8bba<\/h2>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u60a8\u4f7f\u7528\u4e86\u6761\u4ef6\u8bed\u53e5\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b\u3002\u60a8\u5b66\u4f1a\u4e86\u4ec0\u4e48\u65f6\u5019\u9002\u5408\u4f7f\u7528<code>if<\/code>\u548c<code>switch<\/code>\u8bed\u53e5\uff0c\u5e76\u7f16\u5199\u4e86\u4e00\u4e9b\u76f8\u5173\u7684\u4ee3\u7801\u793a\u4f8b\u3002\u60a8\u8fd8\u5b66\u4f1a\u4e86\u7f16\u5199\u5e72\u51c0\u4ee3\u7801\u7684\u6700\u4f73\u5b9e\u8df5\uff0c\u4ee5\u53ca\u5982\u4f55\u907f\u514d\u4e0e\u6761\u4ef6\u8bed\u53e5\u76f8\u5173\u7684\u5e38\u89c1\u9677\u9631\u3002<\/p>\n<p>\u60f3\u8981\u66f4\u591a\u4e86\u89e3Java\uff0c\u8bf7\u67e5\u770b\u6211\u4eec\u7684Java\u7f16\u7a0b\u6307\u5357\u7cfb\u5217\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f5c\u8005\u9009\u62e9\u4e3a\u5199\u4f5c\u6309\u6350\u8d60\u8ba1\u5212\u4e4b\u4e00\u6350\u8d60\u6b3e\u9879\u7ed9\u81ea\u7531\u5f00\u6e90\u57fa\u91d1\u3002 \u5f15\u8a00 \u6761\u4ef6\u8bed\u53e5\u6539\u53d8\u7a0b\u5e8f\u7684\u6d41\u7a0b\u3002\u6761\u4ef6\u8bed\u53e5\u4e5f\u88ab\u79f0\u4e3a\u5206\u652f\u8bed\u53e5\uff0c [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[452,189,453,454,451],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-if-else","tag-java","tag-switch","tag-454","tag-451"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java\u6761\u4ef6\u8bed\u53e5\u7cbe\u901a\u6307\u5357\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528 - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"\u6df1\u5165\u5b66\u4e60Java\u4e2d\u6761\u4ef6\u8bed\u53e5\u7684\u7f16\u5199\u6280\u5de7\uff0c\u5305\u62ecif-else\u3001switch\u548c\u4e09\u5143\u8fd0\u7b97\u7b26\u3002\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u60a8\u638c\u63e1Java\u6761\u4ef6\u903b\u8f91\uff0c\u7f16\u5199\u66f4\u9ad8\u6548\u3001\u66f4\u5065\u58ee\u7684\u4ee3\u7801\uff0c\u63d0\u5347\u7f16\u7a0b\u80fd\u529b\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5982\u4f55\u5728java\u4e2d\u7f16\u5199\u6761\u4ef6\u8bed\u53e5\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u6761\u4ef6\u8bed\u53e5\u7cbe\u901a\u6307\u5357\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528\" \/>\n<meta property=\"og:description\" content=\"\u6df1\u5165\u5b66\u4e60Java\u4e2d\u6761\u4ef6\u8bed\u53e5\u7684\u7f16\u5199\u6280\u5de7\uff0c\u5305\u62ecif-else\u3001switch\u548c\u4e09\u5143\u8fd0\u7b97\u7b26\u3002\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u60a8\u638c\u63e1Java\u6761\u4ef6\u903b\u8f91\uff0c\u7f16\u5199\u66f4\u9ad8\u6548\u3001\u66f4\u5065\u58ee\u7684\u4ee3\u7801\uff0c\u63d0\u5347\u7f16\u7a0b\u80fd\u529b\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5982\u4f55\u5728java\u4e2d\u7f16\u5199\u6761\u4ef6\u8bed\u53e5\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-08T08:01:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-31T14:32:26+00:00\" \/>\n<meta name=\"author\" content=\"\u79d1, \u9896\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u79d1, \u9896\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/\",\"name\":\"Java\u6761\u4ef6\u8bed\u53e5\u7cbe\u901a\u6307\u5357\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2024-03-08T08:01:30+00:00\",\"dateModified\":\"2025-07-31T14:32:26+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/8ca01ba7f7362ad4edb7da206a12f29e\"},\"description\":\"\u6df1\u5165\u5b66\u4e60Java\u4e2d\u6761\u4ef6\u8bed\u53e5\u7684\u7f16\u5199\u6280\u5de7\uff0c\u5305\u62ecif-else\u3001switch\u548c\u4e09\u5143\u8fd0\u7b97\u7b26\u3002\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u60a8\u638c\u63e1Java\u6761\u4ef6\u903b\u8f91\uff0c\u7f16\u5199\u66f4\u9ad8\u6548\u3001\u66f4\u5065\u58ee\u7684\u4ee3\u7801\uff0c\u63d0\u5347\u7f16\u7a0b\u80fd\u529b\u3002\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\u6761\u4ef6\u8bed\u53e5\u7cbe\u901a\u6307\u5357\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/8ca01ba7f7362ad4edb7da206a12f29e\",\"name\":\"\u79d1, \u9896\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8a6fb3cc7ba2f69d2189ba532aec4633ea7ed75ac0af162ec367cb3abc0fb2af?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8a6fb3cc7ba2f69d2189ba532aec4633ea7ed75ac0af162ec367cb3abc0fb2af?s=96&d=mm&r=g\",\"caption\":\"\u79d1, \u9896\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/keying\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Java\u6761\u4ef6\u8bed\u53e5\u7cbe\u901a\u6307\u5357\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528 - Blog - Silicon Cloud","description":"\u6df1\u5165\u5b66\u4e60Java\u4e2d\u6761\u4ef6\u8bed\u53e5\u7684\u7f16\u5199\u6280\u5de7\uff0c\u5305\u62ecif-else\u3001switch\u548c\u4e09\u5143\u8fd0\u7b97\u7b26\u3002\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u60a8\u638c\u63e1Java\u6761\u4ef6\u903b\u8f91\uff0c\u7f16\u5199\u66f4\u9ad8\u6548\u3001\u66f4\u5065\u58ee\u7684\u4ee3\u7801\uff0c\u63d0\u5347\u7f16\u7a0b\u80fd\u529b\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u5982\u4f55\u5728java\u4e2d\u7f16\u5199\u6761\u4ef6\u8bed\u53e5\/","og_locale":"zh_CN","og_type":"article","og_title":"Java\u6761\u4ef6\u8bed\u53e5\u7cbe\u901a\u6307\u5357\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528","og_description":"\u6df1\u5165\u5b66\u4e60Java\u4e2d\u6761\u4ef6\u8bed\u53e5\u7684\u7f16\u5199\u6280\u5de7\uff0c\u5305\u62ecif-else\u3001switch\u548c\u4e09\u5143\u8fd0\u7b97\u7b26\u3002\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u60a8\u638c\u63e1Java\u6761\u4ef6\u903b\u8f91\uff0c\u7f16\u5199\u66f4\u9ad8\u6548\u3001\u66f4\u5065\u58ee\u7684\u4ee3\u7801\uff0c\u63d0\u5347\u7f16\u7a0b\u80fd\u529b\u3002","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u5982\u4f55\u5728java\u4e2d\u7f16\u5199\u6761\u4ef6\u8bed\u53e5\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2024-03-08T08:01:30+00:00","article_modified_time":"2025-07-31T14:32:26+00:00","author":"\u79d1, \u9896","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u79d1, \u9896","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/","name":"Java\u6761\u4ef6\u8bed\u53e5\u7cbe\u901a\u6307\u5357\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2024-03-08T08:01:30+00:00","dateModified":"2025-07-31T14:32:26+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/8ca01ba7f7362ad4edb7da206a12f29e"},"description":"\u6df1\u5165\u5b66\u4e60Java\u4e2d\u6761\u4ef6\u8bed\u53e5\u7684\u7f16\u5199\u6280\u5de7\uff0c\u5305\u62ecif-else\u3001switch\u548c\u4e09\u5143\u8fd0\u7b97\u7b26\u3002\u672c\u6307\u5357\u5c06\u5e2e\u52a9\u60a8\u638c\u63e1Java\u6761\u4ef6\u903b\u8f91\uff0c\u7f16\u5199\u66f4\u9ad8\u6548\u3001\u66f4\u5065\u58ee\u7684\u4ee3\u7801\uff0c\u63d0\u5347\u7f16\u7a0b\u80fd\u529b\u3002","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"Java\u6761\u4ef6\u8bed\u53e5\u7cbe\u901a\u6307\u5357\uff1a\u4ece\u57fa\u7840\u5230\u9ad8\u7ea7\u5e94\u7528"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/8ca01ba7f7362ad4edb7da206a12f29e","name":"\u79d1, \u9896","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8a6fb3cc7ba2f69d2189ba532aec4633ea7ed75ac0af162ec367cb3abc0fb2af?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8a6fb3cc7ba2f69d2189ba532aec4633ea7ed75ac0af162ec367cb3abc0fb2af?s=96&d=mm&r=g","caption":"\u79d1, \u9896"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/keying\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%a6%82%e4%bd%95%e5%9c%a8java%e4%b8%ad%e7%bc%96%e5%86%99%e6%9d%a1%e4%bb%b6%e8%af%ad%e5%8f%a5\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":109542,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/79\/revisions\/109542"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}