Sortest Way to understand Bubble Sort in JAVA - Java2021 : Online Tutorials Hub

Java2021 : Online Tutorials Hub

JAVA | Advance Java | MySQL | Data Structure | Git | HTML | CSS | JS

Latest

Post Top Ad

Tuesday, June 30, 2020

Sortest Way to understand Bubble Sort in JAVA

Bubble Sort Without User Input 
public class BubbleSort {
    public static void main(String[] args) {
        int array[]={5,8,7,3,2,9,6,12,13,15,174,18,200};
        int temp;
        for (int i=0;i<array.length;i++)
        {
            for(int j=0;j<array.length-1;j++){
                if(array[j]>array[j+1]){
                    temp=array[j];
                    array[j]=array[j+1];
                    array[j+1]=temp;
                }
            }
        }
        for (int i=0;i<array.length;i++){
            System.out.print(array[i]+" ");
        }
    }
}
Output : 



Click to next or Searching Programs
Start with your Choice
-Important Programs for Freshers
Learn Pattern Programs 
Click to learn Array Programs
Click to Learn MySQL 
for any complaint regarding my Blog please visit contact us page and write what problem you have!

Learn with us | HTML | CSS | JS | Bootstrap | JAVA | ADV JAVA | SQL | GIT

No comments:

Pages