fork download
  1. /* public */ class BubbleSort {
  2. public static void main(String[] args) {
  3. int[] array = {9, 3, 4, 10, -5};
  4. int[] newArray = sort(array);
  5. for (int value : newArray) {
  6. System.out.println(value);
  7. }
  8. }
  9. public static int[] sort(int[] array) {
  10. int k; int i;
  11. int w;
  12. for (k = 0; k < array.length - 1; k++) {
  13. for (i = array.length - 1; i > k; i--) {
  14. if (array[i - 1] > array[i]) {
  15. w = array[i - 1];
  16. array[i - 1] = array[i];
  17. array[i] = w;
  18. }
  19. }
  20. }
  21. return array;
  22. }
  23. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
-5
3
4
9
10