JAVA冒泡排序/JAVA冒泡排序再找出给定数据中的最大值最小值/JAVA数组排序

 //数组中排序
   int in[] = {1,6,5,8,9};
   Arrays.sort(in);
   for(int i=0;i     System.out.println(in[i]);
  }
   //数组中取最大值,最小值
   int arr[] = {6,3,8,5,7,4,1};
         int min2 = arr[0];
         int temp = 0;
         for(int i=1;i              if(arr[i]                  temp =min2;
                 min2 = arr[i];
                 arr[i] = temp;
             }
         }
         System.out.println("最小"+min2);

      //数组中取最大值,最小值
   int data[]=new int[]{1,3,2,50,60,52};
   int max=data[0],min=data[0];
   for(int i=1;i     if(max      max=data[i];    
    if(min>data[i])      
     min=data[i]; }
   System.out.println("最大值"+max+"最小值"+min);

 ///JAVA冒泡排序

int[] numbs = {10,9,5,2,1,3,8,7,6,4};
  int temp = 0;
  for(int i = 0; i < numbs.length; i++ ){
   for(int j = 0; j < numbs.length - 1; j++){
    if(numbs[i] > numbs[j]){
     temp = numbs[i];
     numbs[i] = numbs[j];
     numbs[j] = temp;
    }
   }
  }
  for(int i = 0 ; i    System.out.println(numbs[i]);
  }

public static void main(String[] args) {
  int[] a = { 5, 21, 6, 88, 60 };

  int temp;
  //升序降序排
  for (int i = 0; i < a.length; i++) {
   for (int j = i + 1; j < a.length; j++) {
    if (a[j] > a[i]) {
     temp = a[i];
     a[i] = a[j];
     a[j] = temp;
    }
   }
  }
  for (int i = 0; i < a.length; i++) {
   System.out.println(a[i]);
  }
  
  System.out.println("选择性排序");
  //选择性排序
  for (int i = 0; i < a.length; i++) {
   for (int j = i + 1; j < a.length; j++) {
    if (a[j] == 60) {
     temp = a[i];
     a[i] = a[j];
     a[j] = temp;
    }
   }
  }
  for (int i = 0; i < a.length; i++) {
   System.out.println(a[i]);
  }
 }

学习资料:百度网盘提取

链接:https://pan.baidu.com/s/1JEYq4Lo8aEms7ClPIchLsA?pwd=dt4z 
提取码:dt4z 

你可能感兴趣的:(JAVA基础,数组,排序,冒泡排序,JAVA)