{"id":551,"date":"2022-09-26T23:35:17","date_gmt":"2022-09-26T15:35:17","guid":{"rendered":"https:\/\/qaqaq.top\/?p=551"},"modified":"2022-11-27T12:40:00","modified_gmt":"2022-11-27T04:40:00","slug":"%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e4%b8%8a-%e8%af%be%e5%90%8e%e7%bb%83%e4%b9%a04%ef%bc%9a%e5%af%b9%e8%b1%a1%e6%95%b0%e7%bb%84%e7%9a%84%e6%94%b9%e8%bf%9b","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=551","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e0a)-\u8bfe\u540e\u7ec3\u4e604\uff1a\u5bf9\u8c61\u6570\u7ec4\u7684\u6539\u8fdb"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P194;\r\n\/*\r\n * 4. \u5bf9\u8c61\u6570\u7ec4\u9898\u76ee\uff1a\r\n\t\u5b9a\u4e49\u7c7bStudent\uff0c\u5305\u542b\u4e09\u4e2a\u5c5e\u6027\uff1a\u5b66\u53f7number(int)\uff0c\u5e74\u7ea7state(int)\uff0c\u6210\u7ee9score(int)\u3002 \r\n\t\u521b\u5efa20\u4e2a\u5b66\u751f\u5bf9\u8c61\uff0c\u5b66\u53f7\u4e3a1\u523020\uff0c\u5e74\u7ea7\u548c\u6210\u7ee9\u90fd\u7531\u968f\u673a\u6570\u786e\u5b9a\u3002\r\n\t\u95ee\u9898\u4e00\uff1a\u6253\u5370\u51fa3\u5e74\u7ea7(state\u503c\u4e3a3\uff09\u7684\u5b66\u751f\u4fe1\u606f\u3002\r\n\t\u95ee\u9898\u4e8c\uff1a\u4f7f\u7528\u5192\u6ce1\u6392\u5e8f\u6309\u5b66\u751f\u6210\u7ee9\u6392\u5e8f\uff0c\u5e76\u904d\u5386\u6240\u6709\u5b66\u751f\u4fe1\u606f\r\n\t\r\n\t\u63d0\u793a\uff1a\r\n\t1) \u751f\u6210\u968f\u673a\u6570\uff1aMath.random()\uff0c\u8fd4\u56de\u503c\u7c7b\u578bdouble; \r\n\t2) \u56db\u820d\u4e94\u5165\u53d6\u6574\uff1aMath.round(double d)\uff0c\u8fd4\u56de\u503c\u7c7b\u578blong\u3002\r\n * \r\n * \r\n * \u6b64\u4ee3\u7801\u662f\u5bf9StudentTest.java\u7684\u6539\u8fdb\uff1a\u5c06\u64cd\u4f5c\u6570\u7ec4\u7684\u529f\u80fd\u5c01\u88c5\u5230\u65b9\u6cd5\u4e2d\u3002\r\n * \r\n * \r\n *\/\r\n\r\n\r\npublic class StudentTest1 {\r\n\tpublic static void main(String&#91;] args) {\r\n\t\t\t\r\n\t\t\/\/\u58f0\u660eStudent\u7c7b\u578b\u7684\u6570\u7ec4\r\n\t\tStudent1&#91;] stus = new Student1&#91;20];\t\/\/String&#91;] arr = new String&#91;10];\r\n\t\t\r\n\t\tfor(int i = 0; i &lt; stus.length; i++) {\r\n\t\t\t\/\/\u7ed9\u6570\u7ec4\u5143\u7d20\u8d4b\u503c\r\n\t\t\tstus&#91;i] = new Student1();\r\n\t\t\t\/\/\u7ed9Student\u5bf9\u8c61\u7684\u5c5e\u6027\u8d4b\u503c\r\n\t\t\tstus&#91;i].number = (i + 1);\r\n\t\t\t\/\/\u5e74\u7ea7\uff1a&#91;1,6]\r\n\t\t\tstus&#91;i].state = (int)(Math.random() * (6 - 1 + 1) + 1);\r\n\t\t\t\/\/\u6210\u7ee9\uff1a&#91;0,100]\r\n\t\t\tstus&#91;i].score = (int)(Math.random() * (100 - 0 + 1));\r\n\t\t}\r\n\t\t\r\n\t\tStudentTest1 test = new StudentTest1();\r\n\t\t\r\n\t\t\/\/\u904d\u5386\u5b66\u751f\u6570\u7ec4\r\n\t\ttest.print(stus);\r\n\t\t\r\n\t\tSystem.out.println(\"***********************************\");\r\n\t\t\r\n\t\t\/\/\u95ee\u9898\u4e00\uff1a\u6253\u5370\u51fa3\u5e74\u7ea7(state\u503c\u4e3a3\uff09\u7684\u5b66\u751f\u4fe1\u606f\u3002\r\n\t\ttest.searchState(stus, 3);\r\n\t\t\r\n\t\tSystem.out.println(\"***********************************\");\r\n\t\t\r\n\t\t\/\/\u95ee\u9898\u4e8c\uff1a\u4f7f\u7528\u5192\u6ce1\u6392\u5e8f\u6309\u5b66\u751f\u6210\u7ee9\u6392\u5e8f\uff0c\u5e76\u904d\u5386\u6240\u6709\u5b66\u751f\u4fe1\u606f\r\n\t\ttest.sort(stus);\r\n\t\t\r\n\t\t\/\/\u904d\u5386\u5b66\u751f\u6570\u7ec4\r\n\t\ttest.print(stus);\r\n\t\t\r\n\t}\r\n\t\r\n\t\/**\r\n\t * \r\n\t* @Description \u904d\u5386Student1&#91;]\u6570\u7ec4\u7684\u64cd\u4f5c\r\n\t* @author RichieZhang\r\n\t* @date 2022\u5e749\u670826\u65e5\u4e0b\u53488:40:37\r\n\t* @param stus\r\n\t *\/\r\n\tpublic void print(Student1&#91;] stus) {\r\n\t\tfor(int i = 0; i &lt; stus.length; i++) {\r\n\t\t\tSystem.out.println(stus&#91;i].info());\r\n\t\t}\r\n\t}\r\n\t\r\n\t\/**\r\n\t * \r\n\t* @Description \u67e5\u627eStudent\u6570\u7ec4\u4e2d\u6307\u5b9a\u5e74\u7ea7\u7684\u5b66\u751f\u4fe1\u606f\r\n\t* @author RichieZhang\r\n\t* @date 2022\u5e749\u670826\u65e5\u4e0b\u53488:36:25\r\n\t* @param stus\t\u8981\u67e5\u627e\u7684\u6570\u7ec4\r\n\t* @param state\t\u8981\u627e\u7684\u5e74\u7ea7\r\n\t *\/\r\n\tpublic void searchState(Student1&#91;] stus,int state) {\r\n\t\tfor(int i = 0;i &lt; stus.length;i++) {\r\n\t\t\tif(stus&#91;i].state == state) {\r\n\t\t\t\tSystem.out.println(stus&#91;i].info());\r\n\t\t\t}\r\n\t\t\t\r\n\t\t}\r\n\t}\r\n\t\r\n\t\/**\r\n\t * \r\n\t* @Description \u7ed9Studnet1\u6570\u7ec4\u6392\u5e8f\r\n\t* @author RichieZhang\r\n\t* @date 2022\u5e749\u670826\u65e5\u4e0b\u53488:39:10\r\n\t* @param stus\r\n\t *\/\r\n\tpublic void sort(Student1&#91;] stus) {\r\n\t\tfor(int i = 0; i &lt; stus.length - 1; i++) {\r\n\t\t\tfor(int j = 0; j &lt; stus.length - 1 - i; j++) {\r\n\t\t\t\tif(stus&#91;j].score > stus&#91;j + 1].score) {\r\n\t\t\t\t\t\/\/\u5982\u679c\u9700\u8981\u6362\u5e8f\uff0c\u4ea4\u6362\u7684\u662f\u6570\u7ec4\u7684\u5143\u7d20\uff1aStudent\u5bf9\u8c61\uff01\uff01\uff01\r\n\t\t\t\t\tStudent1 temp = stus&#91;j];\r\n\t\t\t\t\tstus&#91;j] = stus&#91;j + 1];\r\n\t\t\t\t\tstus&#91;j + 1] = temp;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n}\r\n\r\nclass Student1{\r\n\t\r\n\tint number;\/\/\u5b66\u53f7\r\n\tint state;\/\/\u5e74\u7ea7\r\n\tint score;\/\/\u6210\u7ee9\r\n\t\r\n\t\/\/\u663e\u793a\u5b66\u751f\u4fe1\u606f\u7684\u65b9\u6cd5\r\n\tpublic String info() {\r\n\t\treturn \"\u5b66\u53f7\uff1a\" + number + \",\u5e74\u7ea7\uff1a\" + state + \",\u6210\u7ee9\uff1a\" +score;\r\n\t}\r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-551","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/551"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=551"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/551\/revisions"}],"predecessor-version":[{"id":552,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/551\/revisions\/552"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}