fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void BubbleSort(int[] arr) {
  11. int temp;
  12. for(int i=0;i<arr.length - 1;i++) {
  13. for(int j=0;j <= i;j++) {
  14. if(arr[j] > arr[j+1]) {
  15. temp = arr[j+1];
  16. arr[j+1] = arr[j];
  17. arr[j] = temp;
  18. }
  19. }
  20. }
  21. }
  22. public static void main (String[] args) throws java.lang.Exception
  23. {
  24. int[] data = {4,32,68,1,12,2,9};
  25. BubbleSort(data);
  26. for(int i=0;i<data.length;i++)
  27. System.out.println(data[i]);
  28. }
  29. }
Success #stdin #stdout 0.05s 2184192KB
stdin
Standard input is empty
stdout
1
4
12
2
32
9
68