Home  >  Article  >  Java  >  Methods and examples of bubble sorting in Java

Methods and examples of bubble sorting in Java

WBOY
WBOYforward
2023-04-21 12:31:11959browse

Bubble sort

public class T08 {
    public static void main(String[] args) {
        int[]arr=new int[]{33,55,2,6,-8,-5,66,1,63};
        for(int i=0;i< arr.length-1;i++){
            for(int j=0;j< arr.length-1-i;j++){
                if(arr[j]>arr[j+1]){
                    int a=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=a;
                }
            }
        }
        for(int i=0;i< arr.length;i++) {
                System.out.println(arr[i]);
        }
    }
}

Methods and examples of bubble sorting in Java

The above is the detailed content of Methods and examples of bubble sorting in Java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete