{"id":66937,"date":"2025-05-03T15:39:21","date_gmt":"2025-05-03T07:39:21","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66937\/"},"modified":"2025-05-03T15:39:21","modified_gmt":"2025-05-03T07:39:21","slug":"java%e6%80%8e%e4%b9%88%e6%8a%8a%e6%95%b0%e7%bb%84%e4%b8%ad%e6%98%af%e8%b4%9f%e6%95%b0%e7%9a%84%e5%8f%9806-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66937\/","title":{"rendered":"java\u600e\u4e48\u628a\u6570\u7ec4\u4e2d\u662f\u8d1f\u6570\u7684\u53d806"},"content":{"rendered":"<blockquote><p>\n  \u901a\u8fc7\u904d\u5386\u6570\u7ec4\u5143\u7d20\uff0c\u5c06\u5c0f\u4e8e 0 \u7684\u5143\u7d20\u66ff\u6362\u4e3a 0\u3002\u65b9\u6cd5\u5305\u62ec\uff1a1. \u904d\u5386\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff1b2. \u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u4e3a\u8d1f\u6570\uff1b3. \u5982\u679c\u4e3a\u8d1f\u6570\uff0c\u5219\u7528 0 \u66ff\u6362\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111719422039957.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u628a\u6570\u7ec4\u4e2d\u662f\u8d1f\u6570\u7684\u53d806\u63d2\u56fe\" alt=\"java\u600e\u4e48\u628a\u6570\u7ec4\u4e2d\u662f\u8d1f\u6570\u7684\u53d806\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06 Java \u6570\u7ec4\u4e2d\u8d1f\u6570\u5143\u7d20\u66ff\u6362\u4e3a 0<\/strong><\/p>\n<p><strong>\u65b9\u6cd5\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u904d\u5386\u6570\u7ec4\uff1a<\/strong>\u4f7f\u7528\u4e00\u4e2a\u5faa\u73af\u904d\u5386\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u3002<\/li>\n<li> <strong>\u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\uff1a<\/strong>\u5bf9\u4e8e\u6bcf\u4e2a\u5143\u7d20\uff0c\u68c0\u67e5\u5176\u662f\u5426\u5c0f\u4e8e 0\u3002<\/li>\n<li> <strong>\u82e5\u4e3a\u8d1f\u6570\uff0c\u5219\u66ff\u6362\uff1a<\/strong>\u5982\u679c\u5143\u7d20\u5c0f\u4e8e 0\uff0c\u5219\u4f7f\u7528 0 \u66ff\u6362\u5b83\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>public static void replaceNegativeWithZero(int[] arr) {\n    for (int i = 0; i &lt; arr.length; i++) {\n        if (arr[i] &lt; 0) {\n            arr[i] = 0;\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li>\u58f0\u660e\u5e76\u521d\u59cb\u5316\u4e00\u4e2a\u6570\u7ec4 arr\u3002<\/li>\n<li>\u8c03\u7528 replaceNegativeWithZero \u65b9\u6cd5\uff0c\u4f20\u9012\u6570\u7ec4 arr \u4f5c\u4e3a\u53c2\u6570\u3002<\/li>\n<li>\u6570\u7ec4 arr \u4e2d\u8d1f\u6570\u5143\u7d20\u5c06\u88ab\u66ff\u6362\u4e3a 0\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>int[] arr = {1, -3, 5, -9, 2};\nreplaceNegativeWithZero(arr);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>[1, 0, 5, 0, 2]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u628a\u6570\u7ec4\u4e2d\u662f\u8d1f\u6570\u7684\u53d806\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u901a\u8fc7\u904d\u5386\u6570\u7ec4\u5143\u7d20\uff0c\u5c06\u5c0f\u4e8e 0 \u7684\u5143\u7d20\u66ff\u6362\u4e3a 0\u3002\u65b9\u6cd5\u5305\u62ec\uff1a1. \u904d\u5386\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\uff1b2. \u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u4e3a\u8d1f\u6570\uff1b3. \u5982\u679c\u4e3a\u8d1f\u6570\uff0c\u5219\u7528 0 \u66ff\u6362\u3002 \u5982\u4f55\u5c06 Java \u6570\u7ec4\u4e2d\u8d1f\u6570\u5143\u7d20\u66ff\u6362\u4e3a 0 \u65b9\u6cd5\uff1a \u904d\u5386\u6570\u7ec4\uff1a\u4f7f\u7528\u4e00\u4e2a\u5faa\u73af\u904d\u5386\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u3002 \u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\uff1a\u5bf9\u4e8e\u6bcf\u4e2a\u5143\u7d20\uff0c\u68c0\u67e5\u5176\u662f\u5426\u5c0f\u4e8e 0\u3002 \u82e5\u4e3a\u8d1f\u6570\uff0c\u5219\u66ff\u6362\uff1a\u5982\u679c\u5143\u7d20\u5c0f\u4e8e 0\uff0c\u5219\u4f7f\u7528 0 \u66ff\u6362\u5b83\u3002 \u793a\u4f8b\u4ee3\u7801\uff1a public static void replaceNegativeWithZero(int[] arr) { for (int i = 0; i &lt; arr.length; i++) { if (arr[i] &lt; 0) { arr[i] = 0; } } } \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528\u65b9\u6cd5\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u58f0\u660e\u5e76\u521d\u59cb\u5316\u4e00\u4e2a\u6570\u7ec4 arr\u3002 \u8c03\u7528 [&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-66937","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66937","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=66937"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66937\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}