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


     //数组中排序
       int in[] = {1,6,5,8,9};
       Arrays.sort(in);
       for(int i=0;i<in.length;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<arr.length;i++){
                 if(arr[i]<min2){                
                     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<data.length;i++){   
        if(max<data[i])
         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<numbs.length; i++){ 
       System.out.println(numbs[i]);
      }

  • 相关阅读:
    LN : leetcode 283 Move Zeroes
    LN : Eden Polymorphic And OOP Design Pattern Abstract Factory
    LN : leetcode 242 Valid Anagram
    LN : leetcode 231 Power of Two
    LN : leetcode 191 Number of 1 Bits
    LN : leetcode 263 Ugly Number
    LN : leetcode 258 Add Digits
    LN : leetcode 292 Nim Game
    day5——Python整型、浮点型、布尔型及字符串
    day4——Python运算符
  • 原文地址:https://www.cnblogs.com/dyllove98/p/3225876.html
Copyright © 2020-2023  润新知