Created
February 25, 2025 03:32
-
-
Save Tombert/993ada32270f809bdaa6452065f84bf7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example; | |
import java.util.ArrayList; | |
import java.util.Random; | |
public class Main { | |
public static ArrayList<Integer> createArray(Integer size) { | |
var r = new Random(); | |
var buffer = new ArrayList<Integer>(); | |
for (var i = 0; i < size; i++) { | |
var c = r.nextInt(); | |
buffer.add(c); | |
} | |
return buffer; | |
} | |
public static void swap (ArrayList<Integer> list, Integer indexA, Integer indexB) { | |
var a = list.get(indexA); | |
var b = list.get(indexB); | |
list.set(indexA, b); | |
list.set(indexB, a); | |
} | |
public static void main(String[] args) { | |
var myList = createArray(4); | |
for (var i = 0; i < myList.size(); i++) { | |
for (var j = 0; j < myList.size(); j++) { | |
if (myList.get(i) < myList.get(j)) { | |
swap(myList, i, j); | |
} | |
} | |
} | |
return ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment