Vasilena

ProgrammingExercize040121

Jan 4th, 2021 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. public class CW040121 {
  4.  
  5. public static void main(String[] args) {
  6. int[] intArray = {1,12,4,32,8,7,9,11};
  7. Sort(intArray);
  8. }
  9.  
  10. public static void Sort(int[] intArray){
  11. int temp = 0;
  12. for (int i = 0; i <intArray.length; i++) {
  13. for (int j = i+1; j <intArray.length; j++) {
  14. if(intArray[i] >intArray[j]) { //swap elements if not in order
  15. temp = intArray[i];
  16. intArray[i] = intArray[j];
  17. intArray[j] = temp;
  18. }
  19. }
  20. }
  21. System.out.println(Arrays.toString(intArray));
  22. }
  23. }
  24.  
Add Comment
Please, Sign In to add comment