{"id":558,"date":"2022-09-27T12:57:15","date_gmt":"2022-09-27T04:57:15","guid":{"rendered":"https:\/\/qaqaq.top\/?p=558"},"modified":"2022-11-27T12:39:59","modified_gmt":"2022-11-27T04:39:59","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%e6%96%b0%e7%9a%84%e6%84%9f%e6%82%9f","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=558","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e0a)-\u8bfe\u540e\u7ec3\u4e604\uff1a\u5bf9\u8c61\u6570\u7ec4\u65b0\u7684\u611f\u609f"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P198;\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\npublic class StudentTest {\r\n\tpublic static void main(String&#91;] args) {\r\n\t\tStudent&#91;] stus = new Student&#91;20];\r\n\t\t\r\n\t\tfor(int i = 0; i &lt; stus.length; i++) {\r\n\t\t\tstus&#91;i] = new Student();\r\n\t\t\tstus&#91;i].number = (i + 1);\r\n\t\t\tstus&#91;i].state = (int)(Math.random() * (6 - 1 + 1) + 1);\r\n\t\t\tstus&#91;i].score = (int)(Math.random() * (100 - 0 + 1) + 0);\r\n\t\t\t\r\n\t\t}\r\n\t\t\r\n\t\tStudent test = new Student();\r\n\t\t\r\n\t\ttest.print(stus);\r\n\t\t\r\n\t\tSystem.out.println(\"*******************************\");\r\n\t\t\r\n\t\ttest.searchState(stus,3);\r\n\t\t\r\n\t\tSystem.out.println(\"*******************************\");\r\n\t\t\r\n\t\ttest.sort(stus);\r\n\t\t\r\n\t\ttest.print(stus);\r\n\t}\r\n\r\n}\r\n\r\nclass Student{\r\n\tint number;\r\n\tint state;\r\n\tint score;\r\n\t\r\n\tpublic String info() {\r\n\t\treturn \"\u5b66\u53f7\uff1a\" + number + \",\u5e74\u7ea7\" + state + \",\u6210\u7ee9\" + score;\r\n\t}\r\n\t\r\n\tpublic void print(Student&#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\tpublic void searchState(Student&#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}\r\n\t}\r\n\t\r\n\tpublic void sort(Student&#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\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\t\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\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-558","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\/558"}],"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=558"}],"version-history":[{"count":3,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/558\/revisions"}],"predecessor-version":[{"id":561,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/558\/revisions\/561"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}