This is my code:
int[] p = {1,2,3,4,5};
System.out.print("Even numbers: ");
for (int i = 0; i < p.length; i++) {
if (p[i] == 0) {
} else if (p[i] % 2 == 0) {
System.out.print(p[i] + " ");
}
}
System.out.print("\nOdd numbers: ");
for (int i = 0; i < p.length; i++) {
if (p[i] % 2 != 0) {
System.out.print(p[i] + " ");
}
}
This program prints:
Even numbers: 2 4
Odd numbers: 1 3 5
Next I want to change my code to print something like this:
Even numbers: 2
Odd numbers: 3
This would mean that I want to print the number of even and odd intigers in the array.
How do I do this?