Hey here I have an assignment about sorting. I need create a 500-element array, and data is data is randomly distributed. And next array is data is already in increasing order. Third is in decreasing order. And I'm really confused about how to sort the random number array. Can somebody help me, please?
The code for random: import java.util.Random;
public class SortTest {
public static void main(String[] args) {
// create an instance of Random class for random number generation
Random random = new Random (1L);
// begin new scope
{
// create an int array of 500 elements
int[] dataArray = new int[500];
// populate the array with randomly generated values
for (int index = 0; index < 500; index++)
dataArray[index] = random.nextInt();
// end scope
}
} }
Do I need use Arrays.sort(dataArray)? Or Arrays.sort(dataArray, Collections.reverseOrder())? But I heard somebody said those are not for primary class.
Please help!!! Thank you!!
Aucun commentaire:
Enregistrer un commentaire