Advertisement
Telor_Goreng0

nomor 3 pertemuan 2

Apr 4th, 2021
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. package Pertemuan2;
  2. public class nomor3 {
  3.  
  4.  
  5. public static void main(String[] args) {
  6. System.out.println("3,7,8,1,10");
  7. int[] A = {3,7,8,1,10};
  8. int min, temp, index = 0;
  9. for (int i = 0; i < (A.length - 1); i++) {
  10. min = A[i];
  11. for (int j = (i + 1); j < A.length; j++) {
  12.  
  13. if (A[j] < min) {
  14. min = A[j];
  15. index = j;
  16. }
  17. }
  18. temp = A[i];
  19. A[i] = min;
  20. A[index] = temp;
  21. }
  22. for (int i = 0; i < A.length; i++) {
  23. System.out.println(A[i]);
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement