ok so my code displays 0 every even and odd number can you explain to me how to fix this. i have a feeling it is the displayArray.
This is what dispArray should do
create a method called displayArray that takes an array of integers AND an integer as parameters. The integer length will be used to pass the logical size of the array. The method should then display the contents of the array up to the logical size.
import java.util.Scanner;
public class Arrays1
{
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int[] nums = new int[10];
Scanner sc = new Scanner(System.in);
int [] even = new int[10];
int [] odd = new int[10];
int [] negative = new int[10];
int evenLogicalSize = 0;
int oddLogicalSize = 0;
int negativeLogicalSize = 0;
for(int i = 0; i < 10; i++) {
int c = i + 1;
System.out.print("Input number " + c + ":");
nums[i] = sc.nextInt();
}
for(int i = 0; i < 10; i++)
{
if(nums[i]% 2.0 == 0 || nums[i] == 0 )
{
even[i] = nums[i];
evenLogicalSize++;
}
else
{
odd[i] = nums[i];
oddLogicalSize++;
}
}
for(int i = 0; i < 10; i++)
{
if(nums[i] < 0)
{
negative[i] = nums[i];
negativeLogicalSize++;
}
}
System.out.println();
System.out.print("Even Numbers: ");
displayArray(even, evenLogicalSize);
System.out.println();
System.out.print("Odd Numbers: ");
displayArray(odd, oddLogicalSize);
System.out.println();
System.out.print("Negative Numbers: ");
displayArray(negative, negativeLogicalSize);
}
public static void displayArray (int [] array, int length){
for(int k = 0; k<length; k++){
if(k != length-1){
System.out.print(array[k] + ", ");
} else{
System.out.print(array[k]);
}
}
}
}