Trying to create a random array to be sorted by all the standard sorting algorithms.
I can’t remember how i solved this before, had a recent computer crash and lost my work. i know i have to some how wrap an int array using casting but can’t remember exactly how.
package project6;
import java.util.*;
public class RandomArray
{
Random r;
Integer[] arr100 = new Integer[100];
Integer[] arr1000 = new Integer[1000];
Integer[] arr500K = new Integer[500000];
Integer[] arr1M = new Integer[1000000];
public RandomArray()
{
r = new Random();
}
public Integer[] test100()
{
for( int i=0; i<arr100.length; i++ )
{
r.nextInt( arr100[i] );
}
return arr100;
}
public Integer[] test1000()
{
for( int i=0; i<arr1000.length; i++ )
{
r.nextInt( arr1000[i] );
}
return arr1000;
}
public Integer[] test500K()
{
for( int i=0; i<arr500K.length; i++ )
{
r.nextInt( arr500K[i] );
}
return arr500K;
}
public Integer[] test1M()
{
for( int i=0; i<arr1M.length; i++ )
{
r.nextInt( arr1M[i] );
}
return arr1M;
}
}
I think you have your assignment backwards. Looks like you want to fill up the array with integers so:
With the code you have now you are passing a null value to the r.nextInt(int N) function because the arrays are not populated yet.