Advertisement
javatechie

Bubble Sorting

Aug 20th, 2020
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. public class BubbleSorting {
  2.  
  3.  
  4.     public void sort(int[] array) {
  5.         int temp = 0;
  6.         for (int i = 0; i <= array.length - 1; i++) {
  7.             for (int j = i + 1; j <= array.length - 1; j++) {
  8.                 if (array[i] > array[j]) {
  9.                     temp = array[i];
  10.                     array[i] = array[j];
  11.                     array[j] = temp;
  12.                 }
  13.             }
  14.             System.out.println(array[i]);
  15.         }
  16.     }
  17.  
  18.     public static void main(String[] args) {
  19.         int[] array = {4, 2, 9, 5, 7, 8, 1};
  20.         new BubbleSorting().sort(array);
  21.     }
  22. }
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement