zoukankan      html  css  js  c++  java
  • Java之冒泡排序

    1. 输出数组元素的最大值

    package com.vip.array;
    
    public class ArrayDemo2 {
        public static void main(String[] args) {
            //求数组元素的最大值
            int[] a = {34,23,12,45,78,9,55};
            int max = a[0];
            for(int i=1;i<a.length;i++){
                if(max<a[i]){
                    max = a[i];
                }
            }
            System.out.println("数组中的最大值为:"+max);
        }
    }

    2. 冒泡排序

    package com.vip.array;
    
    public class SortDemo {
        public static void main(String[] args) {
            int[] a = {34,23,12,45,78,9,55};
            int temp;
            for(int i=0;i<a.length-1;i++){
                for(int j=0;j<a.length-i-1;j++){
                    if(a[j]>a[j+1]){
                        temp = a[j];
                        a[j] = a[j+1];
                        a[j+1] = temp;
                    }
                }
            }
            for(int i=0;i<a.length;i++){
                System.out.print(a[i]+" ");
            }
        }
    }
  • 相关阅读:
    v-cloak
    MVVM
    初识ajax
    装瓶学习法
    回调函数(call back)
    如何让学习变得纯粹?
    异步
    grep用法
    Shell中的&&与||的区别
    shell中使用>/dev/null 2>&1 丢弃信息
  • 原文地址:https://www.cnblogs.com/mpp0905/p/11524329.html
Copyright © 2011-2022 走看看