Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





Java - Code Samples

 Sample 1. Write a program for bubble sort.

public class BubbleSort {
   public static void main(String[] args){
      int a[] = {1,3,4,5,7,8,2,6};
      
      for(int i=0;i<a.length-1;i++){
         for(int j=i;j<a.length;j++){
            if(a[j] < a[j]){
               int temporary = a[j];
               a[j] = a[i];
               a[i] = temporary;
            }
         }
      }
      
      for(int i=0;i<a.length;i++){
         System.out.println(a[i]);
      }
   }
}

   Like      Feedback     sorting algorithm  Bubble sort



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner