{"id":66519,"date":"2025-05-03T08:06:51","date_gmt":"2025-05-03T00:06:51","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66519\/"},"modified":"2025-05-03T08:06:51","modified_gmt":"2025-05-03T00:06:51","slug":"java%e6%80%8e%e4%b9%88%e5%af%b9%e6%95%b0%e7%bb%84%e9%9a%8f%e6%9c%ba%e5%88%9d%e5%a7%8b%e5%8c%96-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66519\/","title":{"rendered":"java\u600e\u4e48\u5bf9\u6570\u7ec4\u968f\u673a\u521d\u59cb\u5316"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\uff0c\u4f7f\u7528 random \u7c7b\u4e2d\u7684 nextint() \u65b9\u6cd5\u5bf9\u6570\u7ec4\u8fdb\u884c\u968f\u673a\u521d\u59cb\u5316\uff0c\u751f\u6210\u6307\u5b9a\u8fb9\u754c\u5185\u7684\u968f\u673a\u6570\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u521b\u5efa random \u5bf9\u8c61\uff0c\u904d\u5386\u6570\u7ec4\u4f7f\u7528 nextint() \u65b9\u6cd5\u751f\u6210\u968f\u673a\u6570\uff0c\u5e76\u53ef\u4ee5\u6307\u5b9a\u81ea\u5b9a\u4e49\u7684\u8fb9\u754c\u8303\u56f4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111605363281757.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5bf9\u6570\u7ec4\u968f\u673a\u521d\u59cb\u5316\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5bf9\u6570\u7ec4\u968f\u673a\u521d\u59cb\u5316\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u6570\u7ec4\u968f\u673a\u521d\u59cb\u5316<\/strong><\/p>\n<p><strong>\u5982\u4f55\u5bf9 Java \u4e2d\u7684\u6570\u7ec4\u8fdb\u884c\u968f\u673a\u521d\u59cb\u5316\uff1f<\/strong><\/p>\n<p>\u4f7f\u7528 Random \u7c7b\u4e2d\u7684 nextInt(int bound) \u65b9\u6cd5\u751f\u6210\u968f\u673a\u6570\uff0c\u8303\u56f4\u4e3a\u6307\u5b9a\u8fb9\u754c\u5185\u7684\u6574\u6570\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa Random \u5bf9\u8c61\uff1a<\/strong><\/p>\n<pre>Random random = new Random();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u904d\u5386\u6570\u7ec4\uff0c\u4f7f\u7528 nextInt \u65b9\u6cd5\u751f\u6210\u968f\u673a\u6570\uff1a<\/strong><\/p>\n<pre>int[] numbers = new int[10];\nfor (int i = 0; i &lt; numbers.length; i++) {\n numbers[i] = random.nextInt(100); \/\/ 0 \u5230 99 \u4e4b\u95f4\u7684\u968f\u673a\u6570\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u6307\u5b9a\u81ea\u5b9a\u4e49\u7684\u8fb9\u754c\uff1a<\/strong><br \/>\u8981\u751f\u6210\u7279\u5b9a\u8303\u56f4\u5185\u7684\u968f\u673a\u6570\uff0c\u8bf7\u5728 nextInt \u65b9\u6cd5\u4e2d\u6307\u5b9a\u4e0a\u9650\u548c\u4e0b\u9650\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>for (int i = 0; i &lt; numbers.length; i++) {\n numbers[i] = random.nextInt(100) + 1; \/\/ 1 \u5230 100 \u4e4b\u95f4\u7684\u968f\u673a\u6570\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>import java.util.Random;\n\npublic class RandomArray {\n\n    public static void main(String[] args) {\n        \/\/ \u521b\u5efa\u4e00\u4e2a\u968f\u673a\u5bf9\u8c61\n        Random random = new Random();\n\n        \/\/ \u521d\u59cb\u5316\u4e00\u4e2a\u5927\u5c0f\u4e3a 10 \u7684\u6570\u7ec4\uff0c\u5e76\u8fdb\u884c\u968f\u673a\u521d\u59cb\u5316\n        int[] numbers = new int[10];\n        for (int i = 0; i &lt; numbers.length; i++) {\n            numbers[i] = random.nextInt(100);\n        }\n\n        \/\/ \u6253\u5370\u521d\u59cb\u5316\u540e\u7684\u6570\u7ec4\n        for (int number : numbers) {\n            System.out.println(number);\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u8f93\u51fa\uff1a<\/strong><\/p>\n<pre>23\n57\n91\n44\n15\n72\n97\n2\n53\n67<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5bf9\u6570\u7ec4\u968f\u673a\u521d\u59cb\u5316\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>\u5728 java \u4e2d\uff0c\u4f7f\u7528 random \u7c7b\u4e2d\u7684 nextint() \u65b9\u6cd5\u5bf9\u6570\u7ec4\u8fdb\u884c\u968f\u673a\u521d\u59cb\u5316\uff0c\u751f\u6210\u6307\u5b9a\u8fb9\u754c\u5185\u7684\u968f\u673a\u6570\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u521b\u5efa random \u5bf9\u8c61\uff0c\u904d\u5386\u6570\u7ec4\u4f7f\u7528 nextint() \u65b9\u6cd5\u751f\u6210\u968f\u673a\u6570\uff0c\u5e76\u53ef\u4ee5\u6307\u5b9a\u81ea\u5b9a\u4e49\u7684\u8fb9\u754c\u8303\u56f4\u3002 Java \u4e2d\u6570\u7ec4\u968f\u673a\u521d\u59cb\u5316 \u5982\u4f55\u5bf9 Java \u4e2d\u7684\u6570\u7ec4\u8fdb\u884c\u968f\u673a\u521d\u59cb\u5316\uff1f \u4f7f\u7528 Random \u7c7b\u4e2d\u7684 nextInt(int bound) \u65b9\u6cd5\u751f\u6210\u968f\u673a\u6570\uff0c\u8303\u56f4\u4e3a\u6307\u5b9a\u8fb9\u754c\u5185\u7684\u6574\u6570\u3002 \u8be6\u7ec6\u6b65\u9aa4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u521b\u5efa Random \u5bf9\u8c61\uff1a Random random = new Random(); \u767b\u5f55\u540e\u590d\u5236 \u904d\u5386\u6570\u7ec4\uff0c\u4f7f\u7528 nextInt \u65b9\u6cd5\u751f\u6210\u968f\u673a\u6570\uff1a int[] numbers = new int[10]; for (int i = 0; i &lt; numbers.length; i++) { numbers[i] = random.nextInt(100); \/\/ [&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-66519","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66519","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=66519"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66519\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}