chillurbrain

Task7_6_3

Dec 18th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class Task7_6_3 {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int n = sc.nextInt();
  7. int[] numArr = new int[n];
  8. for (int i = 0; i < n; i++) {
  9. numArr[i] = sc.nextInt();
  10. }
  11. selectionSort(numArr, n);
  12. }
  13. public static void selectionSort(int[] a, int n) {
  14. int min;
  15. for (int i = 0; i < n - 1; i++) {
  16. min = i;
  17. for (int j = i + 1; j < n; j++) {
  18. if (a[j] < a[min])
  19. min = j;
  20. }
  21. //swap (out, min)
  22. int temp = a[i];
  23. a[i] = a[min];
  24. a[min] = temp;
  25. }
  26. for (int i = 0; i < n; i++) {
  27. System.out.print(a[i] + " ");
  28. }
  29. }
  30. }
Add Comment
Please, Sign In to add comment