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

Methods and examples of bubble sorting in Java

WBOY
Release: 2023-04-21 12:31:11
forward
1070 people have browsed it

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]);
        }
    }
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template