import java.util.Arrays;
import java.util.*;
class Main {
public static void main(String[] args) {
}
}
class List {
private static final int NUMINTS = 10;
public List(int numints) {
int list[];
list = new int[NUMINTS];
}
public void fillWithRandom(int list[]) {
Random r;
r = new Random();
int i;
for(i=0; i < NUMINTS ; i++)
list[i] = r.nextInt();
}
public void print(int list[]) {
int i;
System.out.println("before sort():");
for(i=0 ; i < NUMINTS; i++)
System.out.println(list[i]);
Arrays.sort(list, 0, NUMINTS);
System.out.println("--------");
System.out.println("after sort():");
for (i = 0 ; i < NUMINTS; i++)
System.out.println(list[i]);
}
}
I want to create an array of random numbers. I am not quite sure how to implement the methods from my class List into the Main class. I want main to create the array and then print it out.
One problem in your code is that you are not using the argument passed,
Now, come to the point, how you can call methods of
Listclass in yourMainclass’smain()method.Few suggestions,
int[] arr;instead ofint arr[]int[] intArr;in yourListclass. So, you need not passintArrback or forthNUMINTS