Passing Data From One Array To Another
I'm new to java, and I'm creating a program that takes an array with 10 integers and then sorts them into three new arrays of even, odd, and negative numbers, then prints out the three new arrays.
I have code written that sorts the array and prints out one by one each numbers and declares if its even, odd, or negative. However I'm unsure how to pass the data from the original array to each of the new arrays. Here is my code so far.
Code:
public class Arrays81 {
public static void main(String[] args) {
int[] numbers = new int[10];
//int[] evens = new int[10];
//int[] odds = new int[10];
//int[] negatives = new int [10];
numbers[0] = -1;
numbers[1] = -2;
numbers[2] = 5;
numbers[3] = 6;
numbers[4] = 7;
numbers[5] = 8;
numbers[6] = 9;
numbers[7] = 10;
numbers[8] = 11;
numbers[9] = 12;
for (int i = 0; i < numbers.length; i ++){
if (numbers[i] % 2 == 0 & numbers[i] >= 0){
System.out.println(numbers[i] + " is even.");
}
else if (numbers[i] % 1 == 0 & numbers[i] >= 0){
System.out.println(numbers[i] + " is odd.");
}
else{
System.out.println(numbers[i] + " is negative.");
}
}
}
}
Basically I want to know what line of code to add under each if statement to sort the number into the new array. Thanks!
Moderator edit: code tags added