{"id":39573,"date":"2024-11-26T15:40:24","date_gmt":"2024-11-26T07:40:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39573\/"},"modified":"2024-11-26T15:40:24","modified_gmt":"2024-11-26T07:40:24","slug":"java%e6%80%8e%e4%b9%88%e4%b8%80%e8%a1%a8%e6%a0%bc%e5%bd%a2%e5%bc%8f%e8%be%93%e5%87%ba%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39573\/","title":{"rendered":"java\u600e\u4e48\u4e00\u8868\u683c\u5f62\u5f0f\u8f93\u51fa\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u5229\u7528 java \u7684 system.out.printf() \u65b9\u6cd5\uff0c\u53ef\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u4ee5\u8868\u683c\u5f62\u5f0f\u8f93\u51fa\u6570\u7ec4\uff1a\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\u5e76\u521d\u59cb\u5316\u6570\u636e\u3002\u904d\u5386\u6570\u7ec4\uff0c\u4f7f\u7528 &#8220;%4d&#8221; \u683c\u5f0f\u5316\u5e76\u6bcf\u9694 4 \u4e2a\u5b57\u7b26\u8f93\u51fa\u4e00\u4e2a\u7a7a\u683c\u3002\u904d\u5386\u5b8c\u6210\u540e\u6362\u884c\u3002\u6839\u636e\u9700\u8981\uff0c\u53ef\u8bbe\u7f6e\u8f93\u51fa\u683c\u5f0f\uff0c\u4f8b\u5982\u4f7f\u7528 &#8220;%.2f&#8221; \u683c\u5f0f\u5316\u6d6e\u70b9\u6570\u5c0f\u6570\u4f4d\u6570\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111613304799922.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u4e00\u8868\u683c\u5f62\u5f0f\u8f93\u51fa\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u4e00\u8868\u683c\u5f62\u5f0f\u8f93\u51fa\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7528 Java \u4e00\u8868\u683c\u5f62\u5f0f\u8f93\u51fa\u6570\u7ec4<\/strong><\/p>\n<p>\u4e00\u3001\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4<\/p>\n<pre>int[][] arr = new int[][] {\n    {1, 2, 3},\n    {4, 5, 6},\n    {7, 8, 9}\n};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e8c\u3001\u4f7f\u7528 System.out.printf()<\/p>\n<pre>for (int[] row : arr) {\n    for (int value : row) {\n        \/\/ \u6bcf\u9694 4 \u4e2a\u5b57\u7b26\u8f93\u51fa\u4e00\u4e2a\u7a7a\u683c\n        System.out.printf(\"%4d\", value);\n    }\n    System.out.println();  \/\/ \u6362\u884c\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7ed3\u679c\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>   1   2   3\n   4   5   6\n   7   8   9<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e09\u3001\u8bbe\u7f6e\u8f93\u51fa\u683c\u5f0f<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u683c\u5f0f\u5b57\u7b26\u4e32\u6765\u8bbe\u7f6e\u8f93\u51fa\u683c\u5f0f\uff1a<\/p>\n<pre>%n% - \u6574\u6570\n%f - \u6d6e\u70b9\u6570\n%s - \u5b57\u7b26\u4e32\n%-m - \u9650\u5b9a\u8f93\u51fa\u957f\u5ea6\u4e3a m<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u8f93\u51fa\u6d6e\u70b9\u6570\u5e76\u9650\u5b9a\u5c0f\u6570\u4f4d\u6570\u4e3a 2 \u4f4d\uff1a<\/p>\n<pre>System.out.printf(\"%.2f\", 3.14159);  \/\/ \u8f93\u51fa 3.14<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u4e00\u8868\u683c\u5f62\u5f0f\u8f93\u51fa\u6570\u7ec4\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5229\u7528 java \u7684 system.out.printf() \u65b9\u6cd5\uff0c\u53ef\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u4ee5\u8868\u683c\u5f62\u5f0f\u8f93\u51fa\u6570\u7ec4\uff1a\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4\u5e76\u521d\u59cb\u5316\u6570\u636e\u3002\u904d\u5386\u6570\u7ec4\uff0c\u4f7f\u7528 &#8220;%4d&#8221; \u683c\u5f0f\u5316\u5e76\u6bcf\u9694 4 \u4e2a\u5b57\u7b26\u8f93\u51fa\u4e00\u4e2a\u7a7a\u683c\u3002\u904d\u5386\u5b8c\u6210\u540e\u6362\u884c\u3002\u6839\u636e\u9700\u8981\uff0c\u53ef\u8bbe\u7f6e\u8f93\u51fa\u683c\u5f0f\uff0c\u4f8b\u5982\u4f7f\u7528 &#8220;%.2f&#8221; \u683c\u5f0f\u5316\u6d6e\u70b9\u6570\u5c0f\u6570\u4f4d\u6570\u3002 \u5982\u4f55\u7528 Java \u4e00\u8868\u683c\u5f62\u5f0f\u8f93\u51fa\u6570\u7ec4 \u4e00\u3001\u521b\u5efa\u4e8c\u7ef4\u6570\u7ec4 int[][] arr = new int[][] { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} }; \u767b\u5f55\u540e\u590d\u5236 \u4e8c\u3001\u4f7f\u7528 System.out.printf() for (int[] row : arr) { for (int value : row) { \/\/ \u6bcf\u9694 4 \u4e2a\u5b57\u7b26\u8f93\u51fa\u4e00\u4e2a\u7a7a\u683c System.out.printf(&#8220;%4d&#8221;, value); } System.out.println(); \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-39573","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=39573"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39573\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}