I'm trying to create an Integer[] that is increased by a multiple of 10 for each loop. Once the Integer[] size is set I'd like it to fill up the array with random ints. I'm able to get the size of the array to increase, but the values stored within it are null. To me this means the array is resizing correctly, but they elements aren't being assigned to anything. I'm trying a double for-loop, with the inner loop assigning the random values. If there is a better way to do this(which I'm sure there is b/c mine isn't running!) could you please help?
this is my creation of the Int[]
public class TimeComplexity {
Integer[] data;
public TimeComplexity()
{
Random random = new Random();
for (int N = 1000; N <= 1000000; N *= 10)
{
N = random.nextInt(N);
data = new Integer[N];
//checking to see if the random numbers were added.
//array size is okay but locations aren't taking a
//random number
System.out.println(Arrays.toString(data));
}
}
In case you're interested in the output for it my main class. (this isn't part of the question but if you have suggestions I'd love them!)
public class TimeComplexityApp {
private static int MAXSIZE = 1000000;
private static int STARTSIZE = 1000;
public TimeComplexityApp()
{
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
TimeComplexity time = new TimeComplexity();
System.out.println(time);
System.out.printf("%-6s %13s %13s\n\n\n","ARRAY","int","INTEGER");
for (int N = STARTSIZE; N <= MAXSIZE; N *= 10)
{
double d = 1.0;
System.out.printf("\n%-6d %15.2f %15.2f\n", N, d, d);
}
}
}
Aucun commentaire:
Enregistrer un commentaire