- /*
- * Quiz2
- *
- * 实现冒泡算法,对数组元素进行排序
- *
- * 2008年12月13日
- *
- * (Cason_xu)
- */
- import java.util.Scanner;
- class Quiz2 {
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入数组的元素个数:");
- int num = sc.nextInt();
- int[] arraytest = new int[num];
- /*for(int e : arraytest) {
- System.out.println("请依次对数组元素赋值:");
- arraytest[e] = sc.nextInt();
- }
- */
- for(int i = 0 ; i < arraytest.length ; i++){
- arraytest[i] = sc.nextInt();
- }
- for(int i = 0 ; i < num - 1 ; i++){
- for(int j = i+1 ; j < num ; j++){
- if(arraytest [i] < arraytest[j]){
- int t = arraytest [i];
- arraytest [i] = arraytest [j];
- arraytest[j] = t;
- }
- }
- }
- for(int e : arraytest ){
- System.out.println(e + "");
- }
- }
- }
[Java]实现冒泡算法,对数组元素进行排序
最新推荐文章于 2021-02-24 18:12:20 发布