{"id":549,"date":"2022-09-26T23:34:51","date_gmt":"2022-09-26T15:34:51","guid":{"rendered":"https:\/\/qaqaq.top\/?p=549"},"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","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=549","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e0a)-\u8bfe\u540e\u7ec3\u4e604\uff1a\u5bf9\u8c61\u6570\u7ec4"},"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 * \r\n *\/\r\n\r\n\r\npublic class StudentTest {\r\n\tpublic static void main(String&#91;] args) {\r\n\t\t\r\n\/\/\t\tStudent s1 = new Student();\r\n\/\/\t\tStudent s1 = new Student();\r\n\/\/\t\tStudent s1 = new Student();\r\n\/\/\t\tStudent s1 = new Student();\r\n\/\/\t\tStudent s1 = new Student();\r\n\/\/\t\tStudent s1 = new Student();\r\n\t\t\r\n\t\t\/\/\u58f0\u660eStudent\u7c7b\u578b\u7684\u6570\u7ec4\r\n\t\tStudent&#91;] stus = new Student&#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 Student();\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\t\/\/\u904d\u5386\u5b66\u751f\u6570\u7ec4\r\n\t\tfor(int i = 0; i &lt; stus.length; i++) {\r\n\/\/\t\t\tSystem.out.println(stus&#91;i].number + \",\" + stus&#91;i].state \r\n\/\/\t\t\t\t\t+ \",\" + stus&#91;i].score);\r\n\t\t\tSystem.out.println(stus&#91;i].info());\r\n\t\t}\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\tfor(int i = 0;i &lt; stus.length;i++) {\r\n\t\t\tif(stus&#91;i].state == 3) {\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\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\t\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\tStudent 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\t\r\n\t\t\/\/\u904d\u5386\u5b66\u751f\u6570\u7ec4\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\t\r\n\t}\r\n\r\n}\r\n\r\nclass Student{\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-549","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\/549"}],"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=549"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/549\/revisions"}],"predecessor-version":[{"id":550,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/549\/revisions\/550"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}