Advertisement
Guest User

Rangga descending

a guest
Nov 21st, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. class descendin
  2. {
  3. public static void main(String[] args)
  4. {
  5. String [] name={"Kamu","Dia","dan","Aku"};
  6. String temp;
  7. System.out.println("//Sebelum Sorting");
  8. for (int i=0; i<name.length; i++)
  9. {
  10. System.out.println(" "+name[i]+" ");
  11. }
  12.  
  13. for (int i=0; i<(name.length-1); i++)
  14. {
  15. for (int j=0; j<(name.length-1); j++)
  16. {
  17. if (name[j].compareTo(name[j+1])>0)
  18. {
  19. temp=name[j+1];
  20. name[j+1]=name[j];
  21. name[j]=temp;
  22. }
  23. }
  24. }
  25. System.out.println("//Sesudah Sorting");
  26. for (int i=name.length-1; i>=0; i--)
  27. {
  28. System.out.println(" "+name[i]);
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement