Can you please advise how can I pass results from an array to another array without some numbers? In this case without zero numbers. Here is my code, I'm stuck.
Result is: [0, 1, 2, 3, 0, 5, 0, 7, 0, 0, 0, 11] - all I want to do, is to create another array and pass there numbers from above without 0's.
Thanks.
public class SieveOfEratosthenes {
public static void main(String[] args) {
int[] myArray = new int[12];
fillArrayWithNumbers(myArray);
System.out.println(Arrays.toString(sieve(myArray)));
}
private static void fillArrayWithNumbers(int[] myArray) {
for (int i = 0; i < myArray.length; i++) {
myArray[i] = i;
}
}
public static int[] sieve(int[] maximumNumber) {
for (int j = 2; j < maximumNumber.length; j++) {
for (int i = j * 2; i < maximumNumber.length; i += j) {
maximumNumber[i] = 0;
}
}
return maximumNumber;
}
}