Advertisement
bungfaz46

membuat pengurutan dengan java

Jul 4th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. // by abdul fazri ikmi cyber university cirebon
  2. public static void main(String[] args) {
  3. int[] tabInt = {7,5,2,1,4,6,10,9,3,8};
  4. int i,n,temp,tukar;
  5. n=6;
  6.  
  7. //keluarkan data awal
  8. System.out.println("Data Awal");
  9. for(i=0;i<n;i++){
  10. System.out.print(tabInt[i]+ " ");
  11. }
  12. //bubble sort
  13. do{
  14. tukar = 0;
  15. for(i=0; i<(n-1); i++){
  16. if(tabInt[i] > tabInt[i+1]){
  17. temp = tabInt[i];
  18. tabInt[i] = tabInt[i+1];
  19. tabInt[i+1] = temp;
  20. tukar = 1;
  21. }
  22. }
  23. }while(tukar == 1);
  24.  
  25. //keluarkan data terurut
  26. System.out.println("\nData Terurut");
  27. for(i=0;i<n;i++){
  28. System.out.print(tabInt[i]+ " ");
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement