Revised question:
I want the even elements of my array to be stored in a corresponding array. My if else statements do that. Since there will always be a varying number of evens and odds each run, I want the size of the evenArray and oddArray to adjust with each iteration of my while loop. I get an error when compiling that says I'm not doing that part right.
import java.util.Arrays;
import java.util.Random;
public class randomdemo {
public static int[] randommethod()
{
int i = 0;
int[] myArray;
myArray = new int[100];
int[] evenArray;
int[] oddArray;
while(i<=99)
{
Random rand = new Random();
int n = rand.nextInt(25) + 0;
myArray[i] = n;
if(myArray[i] % 2 == 0)
{
evenArray = new int[i];
evenArray[i] = n;
}
else
{
oddArray = new int[i];
oddArray[i] = n;
}
i++;
}
return myArray;
}
public static void main(String args[])
{
int[] result = randommethod();
System.out.println(Arrays.toString(result));
randommethod();
}
}
println). It's therefore expected that nothing is printed out.