{"id":57782,"date":"2024-10-10T21:05:36","date_gmt":"2024-10-10T13:05:36","guid":{"rendered":"https:\/\/server.hk\/cnblog\/57782\/"},"modified":"2024-10-10T21:05:36","modified_gmt":"2024-10-10T13:05:36","slug":"go%e6%95%99%e7%a8%8b-go-%e8%aa%9e%e8%a8%80%e8%bc%b8%e5%87%ba%e4%b9%9d%e4%b9%9d%e4%b9%98%e6%b3%95%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/57782\/","title":{"rendered":"GO\u6559\u7a0b: Go \u8a9e\u8a00\u8f38\u51fa\u4e5d\u4e5d\u4e58\u6cd5\u8868"},"content":{"rendered":"<h1 id=\"go%e6%95%99%e7%a8%8b-go-%e8%aa%9e%e8%a8%80%e8%bc%b8%e5%87%ba%e4%b9%9d%e4%b9%9d%e4%b9%98%e6%b3%95%e8%a1%a8-XojWZnthHK\">GO\u6559\u7a0b: Go \u8a9e\u8a00\u8f38\u51fa\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/h1>\n<p>\u5728\u5b78\u7fd2\u7a0b\u5f0f\u8a9e\u8a00\u7684\u904e\u7a0b\u4e2d\uff0c\u4e5d\u4e5d\u4e58\u6cd5\u8868\u662f\u4e00\u500b\u7d93\u5178\u7684\u7df4\u7fd2\u984c\u76ee\u3002\u5b83\u4e0d\u50c5\u80fd\u5e6b\u52a9\u521d\u5b78\u8005\u719f\u6089\u8a9e\u6cd5\uff0c\u9084\u80fd\u52a0\u6df1\u5c0d\u8ff4\u5708\u548c\u689d\u4ef6\u8a9e\u53e5\u7684\u7406\u89e3\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 Go \u8a9e\u8a00\u4f86\u8f38\u51fa\u4e5d\u4e5d\u4e58\u6cd5\u8868\uff0c\u4e26\u63d0\u4f9b\u8a73\u7d30\u7684\u7a0b\u5f0f\u78bc\u793a\u4f8b\u3002<\/p>\n<h2 id=\"go-%e8%aa%9e%e8%a8%80%e7%b0%a1%e4%bb%8b-XojWZnthHK\">Go \u8a9e\u8a00\u7c21\u4ecb<\/h2>\n<p>Go \u8a9e\u8a00\uff08\u53c8\u7a31 Golang\uff09\u662f\u7531 Google \u958b\u767c\u7684\u4e00\u7a2e\u958b\u6e90\u7a0b\u5f0f\u8a9e\u8a00\u3002\u5b83\u4ee5\u7c21\u6f54\u3001\u9ad8\u6548\u548c\u4e26\u884c\u6027\u8457\u7a31\uff0c\u9069\u5408\u7528\u65bc\u7cfb\u7d71\u7a0b\u5f0f\u8a2d\u8a08\u548c\u7db2\u8def\u670d\u52d9\u958b\u767c\u3002Go \u8a9e\u8a00\u7684\u8a9e\u6cd5\u7c21\u55ae\u6613\u61c2\uff0c\u7279\u5225\u9069\u5408\u521d\u5b78\u8005\u5b78\u7fd2\u3002<\/p>\n<h2 id=\"%e4%b9%9d%e4%b9%9d%e4%b9%98%e6%b3%95%e8%a1%a8%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-XojWZnthHK\">\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u4e5d\u4e5d\u4e58\u6cd5\u8868\u662f\u6578\u5b78\u4e2d\u4e00\u500b\u57fa\u672c\u7684\u4e58\u6cd5\u8868\uff0c\u901a\u5e38\u7528\u65bc\u5e6b\u52a9\u5b78\u751f\u8a18\u61b6\u4e58\u6cd5\u904b\u7b97\u3002\u5b83\u7684\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre>\n1 x 1 = 1\n1 x 2 = 2\n1 x 3 = 3\n...\n9 x 9 = 81\n<\/pre>\n<p>\u5728 Go \u8a9e\u8a00\u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528\u5169\u500b\u5d4c\u5957\u7684\u8ff4\u5708\u4f86\u751f\u6210\u9019\u500b\u8868\u683c\u3002<\/p>\n<h2 id=\"go-%e8%aa%9e%e8%a8%80%e5%af%a6%e7%8f%be%e4%b9%9d%e4%b9%9d%e4%b9%98%e6%b3%95%e8%a1%a8-XojWZnthHK\">Go \u8a9e\u8a00\u5be6\u73fe\u4e5d\u4e5d\u4e58\u6cd5\u8868<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4f7f\u7528 Go \u8a9e\u8a00\u8f38\u51fa\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u7a0b\u5f0f\u78bc\u793a\u4f8b\uff1a<\/p>\n<pre><code>package main\n\nimport \"fmt\"\n\nfunc main() {\n    \/\/ \u5916\u5c64\u8ff4\u5708\u63a7\u5236\u884c\u6578\n    for i := 1; i &lt;= 9; i++ {\n        \/\/ \u5167\u5c64\u8ff4\u5708\u63a7\u5236\u5217\u6578\n        for j := 1; j &lt;= i; j++ {\n            \/\/ \u8f38\u51fa\u4e58\u6cd5\u8868\u7684\u6bcf\u4e00\u9805\n            fmt.Printf(&quot;%d x %d = %dt&quot;, j, i, i*j)\n        }\n        \/\/ \u63db\u884c\n        fmt.Println()\n    }\n}\n<\/code><\/pre>\n<h3 id=\"%e7%a8%8b%e5%bc%8f%e7%a2%bc%e8%a7%a3%e6%9e%90-XojWZnthHK\">\u7a0b\u5f0f\u78bc\u89e3\u6790<\/h3>\n<ul>\n<li><strong>package main<\/strong>: \u5b9a\u7fa9\u4e3b\u5305\uff0cGo \u7a0b\u5f0f\u7684\u5165\u53e3\u3002<\/li>\n<li><strong>import &#8220;fmt&#8221;<\/strong>: \u5f15\u5165 fmt \u5305\uff0c\u7528\u65bc\u683c\u5f0f\u5316\u8f38\u51fa\u3002<\/li>\n<li><strong>func main()<\/strong>: \u5b9a\u7fa9\u4e3b\u51fd\u6578\uff0c\u7a0b\u5f0f\u57f7\u884c\u7684\u8d77\u9ede\u3002<\/li>\n<li><strong>for i := 1; i &lt;= 9; i++<\/strong>: \u5916\u5c64\u8ff4\u5708\uff0c\u63a7\u5236\u884c\u6578\uff0c\u5f9e 1 \u5230 9\u3002<\/li>\n<li><strong>for j := 1; j &lt;= i; j++<\/strong>: \u5167\u5c64\u8ff4\u5708\uff0c\u63a7\u5236\u5217\u6578\uff0c\u5f9e 1 \u5230\u7576\u524d\u884c\u6578 i\u3002<\/li>\n<li><strong>fmt.Printf()<\/strong>: \u683c\u5f0f\u5316\u8f38\u51fa\u6bcf\u4e00\u9805\u7684\u4e58\u6cd5\u7d50\u679c\u3002<\/li>\n<li><strong>fmt.Println()<\/strong>: \u63db\u884c\uff0c\u70ba\u4e0b\u4e00\u884c\u7684\u8f38\u51fa\u505a\u6e96\u5099\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%9f%b7%e8%a1%8c%e7%a8%8b%e5%bc%8f-XojWZnthHK\">\u57f7\u884c\u7a0b\u5f0f<\/h2>\n<p>\u5c07\u4e0a\u8ff0\u7a0b\u5f0f\u78bc\u4fdd\u5b58\u70ba\u4e00\u500b\u540d\u70ba <code>multiplication_table.go<\/code> \u7684\u6a94\u6848\uff0c\u7136\u5f8c\u5728\u7d42\u7aef\u4e2d\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u57f7\u884c\uff1a<\/p>\n<pre><code>go run multiplication_table.go\n<\/code><\/pre>\n<p>\u57f7\u884c\u5f8c\uff0c\u60a8\u5c07\u770b\u5230\u4e5d\u4e5d\u4e58\u6cd5\u8868\u7684\u8f38\u51fa\u7d50\u679c\uff0c\u683c\u5f0f\u6574\u9f4a\uff0c\u4fbf\u65bc\u95b1\u8b80\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-XojWZnthHK\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 Go \u8a9e\u8a00\u8f38\u51fa\u4e5d\u4e5d\u4e58\u6cd5\u8868\uff0c\u901a\u904e\u7c21\u55ae\u7684\u7a0b\u5f0f\u78bc\u793a\u4f8b\uff0c\u5e6b\u52a9\u521d\u5b78\u8005\u7406\u89e3 Go \u8a9e\u8a00\u7684\u57fa\u672c\u8a9e\u6cd5\u548c\u63a7\u5236\u7d50\u69cb\u3002\u5b78\u7fd2\u9019\u4e9b\u57fa\u790e\u77e5\u8b58\u5f8c\uff0c\u60a8\u53ef\u4ee5\u9032\u4e00\u6b65\u63a2\u7d22 Go \u8a9e\u8a00\u7684\u5176\u4ed6\u7279\u6027\uff0c\u5982\u4e26\u884c\u8655\u7406\u548c\u7db2\u8def\u7de8\u7a0b\u7b49\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc\u4f3a\u670d\u5668\u67b6\u8a2d\u6216\u96f2\u7aef\u670d\u52d9\u6709\u8208\u8da3\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4e86\u89e3\u66f4\u591a\u8cc7\u8a0a\uff0c\u63d0\u4f9b\u5404\u7a2e <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u52a9\u60a8\u8f15\u9b06\u642d\u5efa\u81ea\u5df1\u7684\u61c9\u7528\u7a0b\u5f0f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528 Go \u8a9e\u8a00\u8f38\u51fa\u4e5d\u4e5d\u4e58\u6cd5\u8868\uff0c\u638c\u63e1\u57fa\u672c\u8a9e\u6cd5\u8207\u8ff4\u5708\u7d50\u69cb\uff0c\u8f15\u9b06\u5be6\u73fe\u6578\u5b78\u904b\u7b97\u7684\u7a0b\u5f0f\u8a2d\u8a08\u6280\u5de7\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-57782","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=57782"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57782\/revisions"}],"predecessor-version":[{"id":57783,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/57782\/revisions\/57783"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=57782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=57782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=57782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}