Findryan

Untitled

Nov 19th, 2016
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. public class SelectionSort
  2. {
  3. public static void main(String[]args)
  4. {
  5. int a[]={8,5,9,6,3,4,2,1,7,5};
  6. int i=0;
  7. while(i<a.length-1)
  8. {
  9. int tmp=i;
  10. for(int j=i+1;j<a.length;j++)
  11. {
  12. if(a[j]<a[tmp])
  13. tmp=j;
  14. }
  15. int hlp=a[i];
  16. a[i]=a[tmp];
  17. a[tmp]=hlp;
  18. i++;
  19. }
  20. // mencetak hasil
  21. for(int h=0;h<a.length;h++)
  22. {
  23. System.out.println(a[h]+",");
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment