{"id":62,"date":"2015-12-04T19:11:59","date_gmt":"2015-12-04T11:11:59","guid":{"rendered":"http:\/\/www.prayerlaputa.com\/?p=62"},"modified":"2015-12-04T19:11:59","modified_gmt":"2015-12-04T11:11:59","slug":"java%e6%a0%b8%e5%bf%83%e6%8a%80%e6%9c%af%e8%af%bb%e4%b9%a6%e7%ac%94%e8%ae%b0%ef%bc%881%ef%bc%89-%e7%ac%ac3%e7%ab%a0%e5%9f%ba%e6%9c%ac%e7%a8%8b%e5%ba%8f%e8%ae%be%e8%ae%a1%e7%bb%93","status":"publish","type":"post","link":"http:\/\/prayerlaputa.com\/?p=62","title":{"rendered":"Java\u6838\u5fc3\u6280\u672f\u8bfb\u4e66\u7b14\u8bb0\uff081\uff09\u2014\u2014\u7b2c3\u7ae0\u57fa\u672c\u7a0b\u5e8f\u8bbe\u8ba1\u7ed3\u6784"},"content":{"rendered":"<p><strong>3.3 \u6570\u636e\u7c7b\u578b<\/strong><br \/>\nJava\u6709\u4e00\u4e2a\u80fd\u8868\u793a\u4efb\u610f\u7cbe\u5ea6\u7684\u7b97\u672f\u5305\uff0c\u901a\u79f0\u201cbig number\u201d\uff0c\u8be5\u5305\u4e2d\u7684<strong>\u7c7b<\/strong>\u7528\u4e8e\u8868\u793a\u5927\u7684\u6570\u503c\u3002<br \/>\n<strong>3.3.1 \u6574\u578b<\/strong><br \/>\nJava\u4e2d\u6574\u578b\u7684\u8303\u56f4\u4e0e\u8fd0\u884cJava\u4ee3\u7801\u7684\u673a\u5668\u65e0\u5173\uff0c\u5df2\u7ecf\u89c4\u5b9a\u4e86\u5404\u79cd\u6570\u636e\u7c7b\u578b\u6240\u4f7f\u7528\u7684\u5b57\u8282\u6570\u548c\u53d6\u503c\u8303\u56f4\uff08int\u3001short\u3001long\u3001byte\u4f9d\u6b21\u5360\u75284\u30012\u30018\u30011\u4e2a\u5b57\u8282\uff09\u3002Java\u4e2d\u6ca1\u6709\u4efb\u4f55unsigned type\u3002<br \/>\nPS\uff1aC\/C++\u4e2dint\u8868\u793a\u7684\u6574\u578b\u4e0e\u76ee\u6807\u673a\u5668\u6709\u5173\u3002\u8bfb\u300aC\u548c\u6307\u9488\u300b\u7684\u65f6\u5019\u6211\u8bb0\u5f97\u8bfb\u5230\u8fc7\u8fd9\u4e48\u4e00\u53e5\uff1aC\u8bed\u8a00\u89c4\u8303\u53ea\u89c4\u5b9a\u4e86int\u7684\u6700\u5c0f\u53d6\u503c\u8303\u56f4\u3002<!--more--><span id=\"more-518\"><\/span><br \/>\n<strong>3.3.2 \u6d6e\u70b9\u7c7b\u578b<\/strong><br \/>\n\u7edd\u5927\u90e8\u5206\u5e94\u7528\u7a0b\u5e8f\u90fd\u5e94\u91c7\u7528double\u7c7b\u578b\u800c\u4e0d\u662ffloat\u7c7b\u578b\uff0c\u53ea\u6709\u5f88\u5c11\u60c5\u51b5\u9002\u5408\u4f7f\u7528float\u7c7b\u578b\uff0c\u4f8b\u5982\u5feb\u901f\u5730\u5904\u7406\u5355\u7cbe\u5ea6\u6570\u636e\uff0c\u6216\u662f\u9700\u8981\u5b58\u50a8\u5927\u91cf\u6570\u636e\u3002<br \/>\nfloat\u7c7b\u578b\u7684\u6570\u503c\u5fc5\u987b\u6709\u4e00\u4e2a\u540e\u7f00F\uff08\u6bd4\u59823.402F\uff09\uff0c\u6ca1\u6709\u540e\u7f00F\u7684\u6d6e\u70b9\u6570\u503c\uff08\u59823.402\uff09\u9ed8\u8ba4\u4e3adouble\u7c7b\u578b\uff08\u4e5f\u53ef\u4ee5\u52a0\u540e\u7f00D\uff09\u3002<br \/>\nJDK 1.5\u4e2d\u53ef\u4ee5\u4f7f\u7528\u5341\u516d\u8fdb\u5236\u8868\u793a\u6d6e\u70b9\u6570\u503c\uff08\u5177\u4f53\u8868\u793a\u65b9\u5f0f\u8bf7\u53c2\u89c1\u539f\u4e66\uff09\u3002<br \/>\n\u5e38\u91cfDouble.POSITIVE_INFINITY,Double.NEGATIVE_INFINITY,Double.NaN\uff08float\u5bf9\u5e94\u7684\u5e38\u91cf\u4e00\u6837\uff09\u5206\u522b\u8868\u793a\u6b63\u65e0\u7a77\u5927\u3001\u8d1f\u65e0\u7a77\u5927\u3001NaN\uff0c\u7528\u4e8e\u6ea2\u51fa\u548c\u51fa\u9519\u60c5\u51b5\uff08\u5982\u4e00\u4e2a\u6b63\u6570\u9664\u4ee50\u5f97\u5230\u6b63\u65e0\u7a77\u5927\uff0c0\/0\u6216\u662f\u8d1f\u6570\u5e73\u65b9\u6839\u7ed3\u679c\u4e3aNaN\uff09\uff0c\u5b9e\u9645\u5e94\u7528\u4e2d\u5f88\u5c11\u7528\u5230\uff0c\u6ce8\u610f\u4e0d\u80fd\u68c0\u6d4b\u4e00\u4e2a\u7279\u5b9a\u503c\u662f\u5426\u7b49\u4e8eDouble.NaN\uff0c\u6bd4\u5982<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">if(x == Double.NaN)\n<\/pre>\n<p>\u56e0\u4e3a\u6240\u6709\u201cNaN\u201d\u7684\u503c\u90fd\u8ba4\u4e3a\u662f\u4e0d\u76f8\u540c\u7684\uff0c\u6b64\u65f6\u53ef\u4ee5\u7528Double.isNaN\u65b9\u6cd5\u6765\u5224\u522b\u3002<br \/>\n\u6ce8\u610f\uff0c\u6d6e\u70b9\u6570\u503c\u4e0d\u9002\u7528\u4e8e\u7981\u6b62\u51fa\u73b0\u820d\u5165\u8bef\u5dee\u7684\u91d1\u878d\u8ba1\u7b97\u4e2d\u3002<br \/>\nPS\uff1a\u8fd9\u4e2a\u8bed\u6cd5\u70b9\u6709\u65f6\u4f1a\u88ab\u9762\u8bd5\u5b98\u8003\u5230\uff0c\u6bd4\u5982\u95ee\u4f60\u4e24\u4e2adouble\u503c\u6216\u662ffloat\u503c\u662f\u5426\u76f8\u540c\u2014\u2014\u6d6e\u70b9\u6570\u4e00\u822c\u662f\u6ca1\u6cd5\u6bd4\u8f83\u7684\uff0c\u56e0\u4e3a\u91c7\u7528\u7684\u662fIEEE 754\u7684\u8868\u793a\u65b9\u5f0f\uff0c\u6240\u4fdd\u5b58\u7684\u6570\u503c\u5e76\u4e0d\u662f\u7cbe\u786e\u7684\u3002<br \/>\n<strong>3.3.3 char\u7c7b\u578b<\/strong><br \/>\ncode point<br \/>\n\u5efa\u8bae\u4e0d\u8981\u5728\u7a0b\u5e8f\u4e2d\u4f7f\u7528char\u7c7b\u578b\uff0c\u9664\u975e\u786e\u5b9e\u9700\u8981\u5bf9UTF-16\u4ee3\u7801\u4f46\u613f\u8fdb\u884c\u64cd\u4f5c\uff0c\u6700\u597d\u5c06\u9700\u8981\u5904\u7406\u7684\u5b57\u7b26\u4e32\u7528\u62bd\u8c61\u6570\u636e\u7c7b\u578b\u8868\u793a\u3002<br \/>\n<strong>3.3.4 boolean\u7c7b\u578b<\/strong><br \/>\n\u6574\u578b\u503c\u548c\u5e03\u5c14\u503c\u4e4b\u95f4\u4e0d\u80fd\u8fdb\u884c\u76f8\u4e92\u8f6c\u6362\u3002\u8fd9\u4e2a\u548cC\/C++\u660e\u663e\u4e0d\u540c\uff080\u53ef\u4ee5\u8868\u793afalse\uff0c\u975e0\u503c\u8868\u793atrue\uff09\u3002<br \/>\n<strong>3.4 \u53d8\u91cf<\/strong><br \/>\n\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf\u4e4b\u540e\u5fc5\u987b\u7528\u8d4b\u503c\u8bed\u53e5\u5bf9\u53d8\u91cf\u8fdb\u884c\u663e\u5f0f\u8d4b\u503c\u3002<br \/>\n\u53d8\u91cf\u540d\u5fc5\u987b\u662f\u4e00\u4e2a\u4ee5\u5b57\u6bcd\u5f00\u5934\u7684\u7531\u5b57\u6bcd\u3001\u6570\u5b57\u6784\u6210\u7684\u5e8f\u5217\uff0c\u4f46Java\u7684\u201c\u5b57\u6bcd\u201d\u201c\u6570\u5b57\u201d\u8303\u56f4\u6bd4\u5176\u4ed6\u8bed\u8a00\u5927\uff0c\u5b57\u6bcd\u53ef\u4ee5\u662f\u4efb\u4f55\u5728\u67d0\u8bed\u8a00\u4e2d\u4ee3\u8868\u5b57\u6bcd\u7684Unicode\u5b57\u7b26\uff08\u5982\u5fb7\u8bed\u6216\u662f\u5e0c\u814a\u8bed\u03c0\uff09,\u6570\u5b57\u53ef\u4ee5\u662f\u5728\u67d0\u79cd\u8bed\u8a00\u4e2d\u4ee3\u8868\u6570\u5b57\u7684\u4efb\u4f55Unicode\u5b57\u7b26\uff0c\u4f46\u2019+\u2019\u3001\u2019\u5708C\u2019\u3001\u7a7a\u683c\u4e0d\u80fd\u51fa\u73b0\u5728\u53d8\u91cf\u540d\u4e2d\u3002<br \/>\nJava\u4e2d\u53d8\u91cf\u7684\u58f0\u660e\u5c3d\u53ef\u80fd\u5730\u9760\u8fd1\u53d8\u91cf\u7b2c\u4e00\u6b21\u4f7f\u7528\u7684\u5730\u65b9\u3002\uff08PS\uff1a\u60f3\u77e5\u9053\u7f18\u7531\u7684\u8bdd\u53ef\u4ee5\u53bb\u770bEffective Java\uff09<br \/>\nC\/C++\u4e2d\u533a\u5206\u53d8\u91cf\u7684\u58f0\u660e\uff08\u5982extern int i\uff09\u548c\u5b9a\u4e49\uff08\u5982int i \u00a0= 10\uff09\uff0c\u800cJava\u4e2d\u4e0d\u533a\u5206\u8fd9\u4e00\u70b9\u3002<br \/>\n<strong>3.5 \u8fd0\u7b97\u7b26<\/strong><br \/>\n<strong>3.5.3 \u4f4d\u8fd0\u7b97\u7b26<\/strong><br \/>\n\u201c&gt;&gt;&gt;\u201d\u5c06\u75280\u586b\u5145\u9ad8\u4f4d\uff0c\u201d&gt;&gt;\u201d\u7528\u7b26\u53f7\u4f4d\u586b\u5145\u9ad8\u4f4d\u3002\u6ca1\u6709\u201d&lt;&lt;&lt;\u201c\u3002\u6ce8\u610f\uff1a\u5bf9\u79fb\u4f4d\u8fd0\u7b97\u7b26\u53f3\u4fa7\u7684\u53c2\u6570\u9700\u8981\u8fdb\u884c\u6a2132\u64cd\u4f5c\uff08\u9664\u975e\u5de6\u8fb9\u7684\u64cd\u4f5c\u6570\u662flong\u7c7b\u578b\uff0c\u6b64\u65f6\u8fdb\u884c\u6a2164\u64cd\u4f5c\uff09\uff0c\u59821&lt;&lt;35\u4e0e1&lt;&lt;3\u7684\u7ed3\u679c\u662f\u76f8\u540c\u7684\u3002\u800cC\/C++\u4e2d\u65e0\u6cd5\u786e\u5b9a\u662f\u7b97\u672f\u79fb\u4f4d\uff08\u6269\u5c55\u7b26\u53f7\u4f4d\uff09\u8fd8\u662f\u903b\u8f91\u79fb\u4f4d\uff08\u9ad8\u4f4d\u586b0\uff09\u3002\u6267\u884c\u4e2d\u5c06\u4f1a\u9009\u53d6\u6548\u7387\u8f83\u9ad8\u7684\u4e00\u79cd\uff0c\u8fd9\u5c31\u610f\u5473\u7740\uff0c\u5728C\/C++\u4e2d\uff0c&gt;&gt;\u5b9e\u9645\u4e0a\u53ea\u662f\u4e3a\u975e\u8d1f\u6570\u5b9a\u4e49\u7684\uff0c\u800cJava\u5219\u6d88\u9664\u4e86\u8fd9\u79cd\u6a21\u7cca\u3002<br \/>\n<strong>3.5.4 \u6570\u636e\u51fd\u6570\u4e0e\u5e38\u91cf<\/strong><br \/>\n\u4eceJDK 1.5\u5f00\u59cb\u53ef\u4ee5\u4e0d\u5fc5\u4f7f\u7528\u201cMath.XXX()\u201d\u7684\u8c03\u7528\u65b9\u5f0f\uff0c\u5728\u6e90\u6587\u4ef6\u5934\u90e8\u5f15\u5165Math\u5305\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528\u6570\u5b66\u65b9\u6cd5\u6216\u662f\u5e38\u91cf\u3002<br \/>\n<strong>3.5.5 \u6570\u7ec4\u7c7b\u578b\u4e4b\u95f4\u7684\u8f6c\u6362<\/strong><br \/>\n\u4e8c\u5143\u8fd0\u7b97\u4e2d\uff0c\u4e24\u4e2a\u64cd\u4f5c\u6570\u4e2d\uff1a<\/p>\n<ul>\n<li>\u82e5\u6709\u4e00\u4e2a\u662fdouble\u7c7b\u578b\uff0c\u5219\u53e6\u4e00\u4e2a\u8f6c\u6362\u4e3adouble\u7c7b\u578b<\/li>\n<li>\u5426\u5219\uff0c\u82e5\u6709\u4e00\u4e2a\u662ffloat\u7c7b\u578b\uff0c\u5219\u53e6\u4e00\u4e2a\u8f6c\u6362\u4e3afloat\u7c7b\u578b<\/li>\n<li>\u5426\u5219\uff0c\u82e5\u6709\u4e00\u4e2a\u662flong\u7c7b\u578b\uff0c\u5219\u53e6\u4e00\u4e2a\u8f6c\u6362\u4e3along\u7c7b\u578b<\/li>\n<li>\u5426\u5219\uff0c\u4e24\u4e2a\u64cd\u4f5c\u6570\u90fd\u5c06\u88ab\u8f6c\u6362\u4e3aint\u7c7b\u578b\u3002<\/li>\n<\/ul>\n<p><strong>3.5.6 \u5f3a\u5236\u7c7b\u578b\u8f6c\u6362<\/strong><br \/>\nJava\u4e2d\u5141\u8bb8\u5404\u79cd\u6570\u503c\u7c7b\u578b\u4e4b\u95f4\u7684\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\uff0c\u4f46\u53ef\u80fd\u4f1a\u4e22\u5931\u4e00\u4e9b\u4fe1\u606f\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">double x = 9,997;\nint nx = (int)x;\n<\/pre>\n<p>\u6b64\u65f6\uff0cnx\u7684\u503c\u4e3a9\u3002\u8fd9\u662f\u56e0\u4e3a\uff0c<strong>\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\u901a\u8fc7\u622a\u65ad\u5c0f\u6570\u90e8\u5206\u5c06\u6d6e\u70b9\u503c\u8f6c\u6362\u4e3a\u6574\u578b\u3002<\/strong>\u5982\u679c\u8981\u5bf9\u6d6e\u70b9\u6570\u8fdb\u884c\u820d\u5165\u8fd0\u7b97\uff0c\u4ee5\u4fbf\u5f97\u5230\u6700\u63a5\u8fd1\u7684\u6574\u6570\u65f6\uff0c\u9700\u8981\u4f7f\u7528Math.round()\u65b9\u6cd5\uff1a<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">double x = 9,997;\nint nx = (int)Math.round(x);\n<\/pre>\n<p>\u6b64\u65f6nx\u7684\u503c\u4e3a10\u3002\u800c\u4f7f\u7528round()\u65b9\u6cd5\u4ecd\u9700\u8981\u4f7f\u7528\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362\uff08int\uff09\u5219\u662f\u56e0\u4e3a\u8be5\u65b9\u6cd5\u8fd4\u56de\u7684\u7ed3\u679c\u662flong\u7c7b\u578b\u3002<br \/>\n<strong>3.6 \u5b57\u7b26\u4e32<\/strong><br \/>\n<strong>3.6.1 \u5b50\u4e32<\/strong><br \/>\nsubstring()\u65b9\u6cd5\u5b9e\u9645\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\u3002<br \/>\n<strong>3.6.3 \u4e0d\u53ef\u53d8\u5b57\u7b26\u4e32<\/strong><br \/>\n\u4e0d\u80fd\u4fee\u6539Java\u5b57\u7b26\u4e32\u4e2d\u7684\u5b57\u7b26\uff0c\u56e0\u6b64String\u7c7b\u5bf9\u8c61\u88ab\u79f0\u4e3a<strong>\u4e0d\u53ef\u53d8\u5b57\u7b26\u4e32<\/strong>\u3002\u4e0d\u53ef\u53d8\u5b57\u7b26\u4e32\u6709\u4e00\u4e2a\u4f18\u70b9\uff1a\u7f16\u8bd1\u5668\u53ef\u4ee5\u8ba9\u5b57\u7b26\u4e32\u5171\u4eab\u3002<br \/>\nPS\uff1aC++\u5b57\u7b26\u4e32\u662f\u53ef\u4fee\u6539\u7684\uff08\u53ef\u4ee5\u4fee\u6539\u5355\u4e2a\u5b57\u7b26\uff09\u3002<br \/>\n<strong>3.6.4 \u68c0\u6d4b\u5b57\u7b26\u4e32\u662f\u5426\u76f8\u7b49<\/strong><br \/>\n\u4e00\u5b9a\u4e0d\u80fd\u7528==\u6765\u68c0\u6d4b\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u76f8\u5f53\uff0c\u8be5\u64cd\u4f5c\u7b26\u53ea\u80fd\u5224\u65ad\u4e24\u4e2a\u5b57\u7b26\u4e32\u662f\u5426\u653e\u7f6e\u5728\u540c\u4e00\u4e2a\u4f4d\u7f6e\u4e0a\u3002<br \/>\n<strong>3.6.8 \u6784\u5efa\u5b57\u7b26\u4e32<\/strong><br \/>\n\u5982\u679c\u9700\u8981\u5bf9\u5b57\u7b26\u4e32\u8fdb\u884c\u4fee\u6539\uff0c\u5e94\u8be5\u4f7f\u7528StringBuilder\u7c7b\uff08JDK 1.5\u5f15\u5165\uff09\u3002\u8be5\u7c7b\u524d\u8eab\u662fStringBuffer\uff0c\u6548\u7387\u6709\u4e9b\u4f4e\uff0c\u4f46\u5141\u8bb8\u591a\u7ebf\u7a0b\u6267\u884c\u6dfb\u52a0\/\u5220\u9664\u5b57\u7b26\u7684\u64cd\u4f5c\u3002\u82e5\u5728\u5355\u7ebf\u7a0b\u73af\u5883\u4e0b\u5e94\u8be5\u7528StringBuilder\u3002<br \/>\n<strong>3.7 \u8f93\u5165\u8f93\u51fa<\/strong><br \/>\n<strong>3.7.1 \u8bfb\u53d6\u8f93\u5165<\/strong><br \/>\nScanner in = new Scanner(System.in);<br \/>\nScanner\u7684\u8f93\u5165\u662f\u53ef\u89c1\u7684\uff0c\u4e0d\u9002\u5408\u4ece\u63a7\u5236\u53f0\u8bfb\u53d6\u5bc6\u7801\uff0cJava SE 6\u5f15\u5165\u4e86Console\u7c7b\u5b9e\u73b0\u8be5\u76ee\u7684\uff1a<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">Console cons \u00a0= System.console();\nString username = cons.readLine(\"user name:\");\nchar[] passwd = cons.readPasswd(\"Password:\");\n<\/pre>\n<p><strong>3.7.2 \u683c\u5f0f\u5316\u8f93\u51fa<\/strong><br \/>\nJava SE 5\u6cbf\u7528\u4e86C\u8bed\u8a00\u51fd\u6570\u4e2d\u7684printf\u65b9\u6cd5\uff0c\u53ef\u4ee5\u7528\u4e8e\u683c\u5f0f\u5316\u8f93\u51fa\u3002<br \/>\n\u53ef\u4ee5\u4f7f\u7528\u9759\u6001\u7684String.format\u65b9\u6cd5\u521b\u5efa\u4e00\u4e2a\u683c\u5f0f\u5316\u7684\u5b57\u7b26\u4e32\uff0c\u800c\u4e0d\u6253\u5370\u8f93\u51fa\u3002<br \/>\n<strong>3.7.3 \u6587\u4ef6\u7684\u8f93\u5165\u4e0e\u8f93\u51fa<\/strong><br \/>\n\u8bfb\u6587\u4ef6\uff1a<br \/>\nScanner in = new Scanner(new File(\u201cmyfile.txt\u201d));<br \/>\n\u5199\u6587\u4ef6\uff1a<br \/>\nPrintWriter out = new PrintWriter(\u201cmyfile.txt\u201d);<br \/>\n\u6ce8\u610f\uff0c\u5982\u679c\u7528\u4e00\u4e2a\u4e0d\u5b58\u5728\u7684\u6587\u4ef6\u6784\u9020\u4e00\u4e2aScanner\uff0c\u6216\u662f\u7528\u4e00\u4e2a\u4e0d\u80fd\u88ab\u521b\u5efa\u7684\u6587\u4ef6\u540d\u6784\u9020\u4e00\u4e2aPrintWriter\uff0c\u5219\u4f1a\u53d1\u751f\u5f02\u5e38\u3002<br \/>\n<strong>3.8 \u63a7\u5236\u6d41\u7a0b<\/strong><br \/>\n\u5faa\u73af\u4e2d\u68c0\u6d4b2\u4e2a\u6d6e\u70b9\u6570\u662f\u5426\u76f8\u5f53\u9700\u8981\u683c\u5916\u5c0f\u5fc3\u3002\u5982\uff1a<br \/>\nfor(double x = 0; x!=10; x+=0.1)<br \/>\n\u53ef\u80fd\u6c38\u8fdc\u4e0d\u4f1a\u7ed3\u675f\u3002\u7531\u4e8e\u820d\u5165\u8bef\u5dee\uff0c\u6700\u7ec8\u53ef\u80fd\u5f97\u4e0d\u5230\u7cbe\u786e\u503c\u3002x\u4f1a\u4ece9.99999\u2026\u76f4\u63a5\u8df3\u523010.09999\u2026<br \/>\nfor\u5faa\u73af\u8bed\u53e5\u53ef\u4ee5\u770b\u505a\u662fwhile\u5faa\u73af\u7684\u4e00\u79cd\u7b80\u5316\u5f62\u5f0f\u3002<br \/>\n\u5f53\u5728switch\u8bed\u53e5\u4e2d\u4f7f\u7528\u679a\u4e3e\u5e38\u91cf\u65f6\uff0c\u4e0d\u5fc5\u5728\u6bcf\u4e2a\u6807\u7b7e\u4e2d\u6307\u660e\u679a\u4e3e\u540d\uff0c\u53ef\u4ee5\u7531switch\u8868\u8fbe\u5f0f\u503c\u786e\u5b9a\uff0c\u4f8b\u5982\uff1a<br \/>\nSize sz = \u2026;<br \/>\nswitch(sz){<br \/>\ncase SMALL:<br \/>\n\u2026<br \/>\n}<br \/>\n\u53ef\u4ee5\u5229\u7528break <em>label<\/em>;\u7684\u65b9\u5f0f\u5b9e\u73b0goto\u7684\u529f\u80fd\u3002<br \/>\n<strong>3.10 \u6570\u7ec4<\/strong><br \/>\nfor each\u5faa\u73af\u2014\u2014\u64cd\u4f5c\u5bf9\u8c61\u5fc5\u987b\u662f\u4e00\u4e2a\u6570\u7ec4\u6216\u662f\u4e00\u4e2a\u5b9e\u73b0\u4e86Iterator\u89e3\u8026\u7684\u7c7b\u5bf9\u8c61\u3002<br \/>\n\u6570\u7ec4\u521d\u59cb\u5316\uff1a<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">int[] smallPrimes = {2,3,5,7,11,13};\n<\/pre>\n<p>\u533f\u540d\u7684\u6570\u7ec4\uff1anew int[]{17,19,23}; \u2014\u2014\u8fd9\u79cd\u8bed\u6cd5\u53ef\u4ee5\u5728\u4e0d\u521b\u5efa\u65b0\u53d8\u91cf\u7684\u60c5\u51b5\u4e0b\u91cd\u65b0\u521d\u59cb\u5316\u4e00\u4e2a\u6570\u7ec4\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">int[] smallPrimes =\u00a0new int[]{17,19,23};\n<\/pre>\n<p>Java\u4e2d\u5141\u8bb8\u6570\u7ec4\u957f\u5ea6\u4e3a0\uff0c\u6570\u7ec4\u957f\u5ea6\u4e3a0\u4e0enull\u4e0d\u540c\u3002<br \/>\n\u6570\u7ec4\u53d8\u91cf\u76f4\u63a5\u8d4b\u503c\u5c06\u4f1a\u4f7f\u5f97\u4e24\u4e2a\u53d8\u91cf\u5f15\u7528\u540c\u4e00\u4e2a\u6570\u7ec4\uff0c\u8981\u60f3\u5c06\u6570\u636e\u62f7\u8d1d\u5230\u4e00\u4e2a\u65b0\u6570\u7ec4\uff0c\u53ef\u4ee5\u7528Arrays\u7c7b\u7684copyOf\u65b9\u6cd5\u3002<br \/>\n\u6570\u7ec4\u6392\u5e8f\u53ef\u4ee5\u4f7f\u7528Arrays\u7c7b\u4e2d sort\u65b9\u6cd5\uff08\u5185\u90e8\u5b9e\u73b0\u91c7\u7528\u4e86\u4f18\u5316\u7684\u5feb\u6392\uff09\u3002<br \/>\n<strong>3.10.6 \u591a\u7ef4\u6570\u7ec4<\/strong><br \/>\n\u591a\u7ef4\u6570\u7ec4\u58f0\u660e\uff1a<br \/>\ndouble[][] balances;<br \/>\n\u521d\u59cb\u5316\uff1a<br \/>\nbalances = new double[NYEARS][NRATES];<br \/>\n\u7b80\u5316\u5f62\u5f0f\uff1a<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">int[][] magicSquare = {\n{16,3,2},\n{12,1,5},\n{9,8,6}\n};\n<\/pre>\n<p>for each\u5faa\u73af\u8bed\u53e5\u4e0d\u80fd\u81ea\u52a8\u5904\u7406\u4e8c\u7ef4\u6570\u7ec4\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\uff0c\u5b83\u662f\u6309\u7167\u884c\uff0c\u5373\u4e00\u7ef4\u6570\u7ec4\u5904\u7406\u7684\u3002\u60f3\u8981\u8bbf\u95ee\u4e8c\u7ef4\u6570\u7ec4\u6240\u6709\u5143\u7d20\uff0c\u9700\u8981\u5d4c\u5957\u7684\u5faa\u73af\uff1a<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">for(double[] row:a)\nfor(double value:row)\ndo sth\n<\/pre>\n<p>\u7531\u4e8e\u53ef\u4ee5\u5355\u72ec\u7684\u5b58\u53d6\u4e00\u884c\uff0c\u6240\u4ee5\u53ef\u4ee5\u8ba9\u4e8c\u7ef4\u6570\u7ec4\u4e2d2\u884c\u4ea4\u6362\u3002<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">double[] tmp = balances[i];\nbalances[i]= balances[i+1];\nbalances[i+1] = tmp;\n<\/pre>\n<p>Java\u4e2d\u53ef\u4ee5\u521b\u5efa\u4e0d\u89c4\u5219\u7684\u6570\u7ec4\u3002<br \/>\n&lt;br\/&gt;<br \/>\n<strong>3.10.4 \u547d\u4ee4\u884c\u53c2\u6570<\/strong><br \/>\nJava\u7a0b\u5e8f\u7684main\u65b9\u6cd5\u4e2d\uff0c\u7a0b\u5e8f\u540d\u5e76\u6ca1\u6709\u5b58\u50a8\u5728args\u6570\u7ec4\u4e2d\uff0c\u4f8b\u5982\uff1ajava Message -h world \u4e2d\uff0cargs[0]\u662f\u201c-h\u201d\uff0c\u800c\u4e0d\u662f\u201dMessage\u201d\u6216\u662f\u201cjava\u201d\u3002<br \/>\n<strong>\u6709\u7528\u7684API\uff1a<\/strong><br \/>\nString\u7c7b\uff1a<\/p>\n<ul>\n<li>String trim() \u5220\u9664\u539f\u59cb\u5b57\u7b26\u4e32\u5934\u90e8\u548c\u5c3e\u90e8\u7684\u7a7a\u683c\u3002<\/li>\n<\/ul>\n<p>Arrays\u7c7b\uff1a<\/p>\n<ul>\n<li>copyOf \u62f7\u8d1d\u6570\u7ec4<\/li>\n<li>sort \u5bf9\u6570\u7ec4\u6392\u5e8f<\/li>\n<li>binarySearch \u5728\u6570\u7ec4\u4e2d\u4e8c\u5206\u67e5\u627e<\/li>\n<li>fill \u586b\u5145\u6240\u6709\u6570\u7ec4\u5143\u7d20\u4e3aXXX<\/li>\n<li>equal \u5224\u65ad\u4e24\u4e2a\u6570\u7ec4\u4e0b\u6807\u662f\u5426\u76f8\u7b49<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>3.3 \u6570\u636e\u7c7b\u578b Java\u6709\u4e00\u4e2a\u80fd\u8868\u793a\u4efb\u610f\u7cbe\u5ea6\u7684\u7b97\u672f\u5305\uff0c\u901a\u79f0\u201cbig number\u201d\uff0c\u8be5\u5305\u4e2d\u7684\u7c7b\u7528\u4e8e\u8868\u793a\u5927\u7684\u6570 <a href='http:\/\/prayerlaputa.com\/?p=62' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[6,12,23],"tags":[33,44,55],"_links":{"self":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/62"}],"collection":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=62"}],"version-history":[{"count":0,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=\/wp\/v2\/posts\/62\/revisions"}],"wp:attachment":[{"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/prayerlaputa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}