{ "question_id": 7455237, "question_title": "数组排序", "question_content": "<p>编写一个JavaApplication程序,将随机生成的无序数组使用冒泡排序,将这个混乱的数组变成一个从小到大排列的有序的数组并输出。</p>", "difficulty": "简单", "answer_id": 53438050, "answer_content": "<p>其实就是个冒泡排序呗</p>\n\n<pre>\n<code class=\"language-java\">class demo_sort {\n public static void main(String[] args) {\n //冒泡排序算法\n int[] numbers=new int[]{1,5,8,2,3,9,4};\n //需进行length-1次冒泡\n for(int i=0;i<numbers.length-1;i++)\n {\n for(int j=0;j<numbers.length-1-i;j++)\n {\n if(numbers[j]>numbers[j+1])\n {\n int temp=numbers[j];\n numbers[j]=numbers[j+1];\n numbers[j+1]=temp;\n }\n }\n }\n System.out.println("从小到大排序后的结果是:");\n for(int i=0;i<numbers.length;i++)\n System.out.print(numbers[i]+" ");\n }\n }</code></pre>\n\n<p> </p>\n", "tag_name": "java", "java": "class demo_sort {\n\tpublic static void main(String[] args) {\n\t\tint[] numbers = new int[] { 1, 5, 8, 2, 3, 9, 4 };\n\t\tfor (int i = 0; i < numbers.length - 1; i++) {\n\t\t\tfor (int j = 0; j < numbers.length - 1 - i; j++) {\n\t\t\t\tif (numbers[j] > numbers[j + 1]) {\n\t\t\t\t\tint temp = numbers[j];\n\t\t\t\t\tnumbers[j] = numbers[j + 1];\n\t\t\t\t\tnumbers[j + 1] = temp;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(\"从小到大排序后的结果是:\");\n\t\tfor (int i = 0; i < numbers.length; i++)\n\t\t\tSystem.out.print(numbers[i] + \" \");\n\t}\n}", "topic_link": "https://bbs.csdn.net/topics/600470289", "status": 1, "keywords": "图算法,算法高阶,最小生成树,最小生成树的形成", "license": "csdn.net", "notebook": { "java": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/java/34.ipynb?type=file" }, "notebook_enable": 1 }