如何将 randomNumbers 的值转换为数组集,以便以后使用它们进行排序?
这是我的主要课程
import java.util.Arrays;
import java.util.*;
public class Main {
public static void main(String[] args){
int choice;
int g;
Scanner input=new Scanner(System.in);
System.out.println("Enter how many random no:");
g=input.nextInt();
RandomAlgo ran=new RandomAlgo();
g=ran.randomNum(g);
RandomAlgo rand=new RandomAlgo();
int[] data=rand.randomNum(randomNumbers); //did i did this right here?
System.out.println("Choose Sorting algorithm: \n (1)Selection Sort \n (2)Insertion Sort \n (3)Bubble Sort \n (4)Quick Sort" );
choice=input.nextInt();
switch(choice){
case 1:{
SortingAlgo algo=new SortingAlgo();
data=algo.selectionSort(data);
break;
}
对于我的随机数类,这里是我的代码。我的问题是如何将值传递randomNumbers
给我的主类?
public class RandomAlgo extends Main{
public int randomNum(int g){
Random rand = new Random();
int e;
int i;
HashSet<Integer> randomNumbers = new HashSet<Integer>();
for (i = 0; i < g; i++) {
e = rand.nextInt(1000);
randomNumbers.add(e);
if (randomNumbers.size() <= 0) {
if (randomNumbers.size() == 0) {
g = g;
}
g++;
randomNumbers.add(e);
}
}
System.out.println("Random numbers Are : " +randomNumbers);
return g;
}
}