Advertisement
16112

Bubble sort

Mar 17th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. public class project {
  4.      static void bubbleSort(int[] arr) {
  5.             for (int j = 0; j < arr.length; j++) {
  6.                 for (int i = 0; i < arr.length - 1 - j; i++) {
  7.                     if (arr[i] < arr[i + 1]) {
  8.                         int temp = arr[i];
  9.                         arr[i] = arr[i + 1];
  10.                         arr[i + 1] = temp;
  11.                     }
  12.                 }
  13.             }
  14.         }
  15.      
  16.         public static void main(String[] args) {
  17.             int[] numbers = { 121, 32, -2, 3, 34, 340, 3, -34, 3 };
  18.             bubbleSort(numbers);
  19.             System.out.println(Arrays.toString(numbers));
  20.         }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement