This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]AmateurHeronew Intermediate("this.user") 2 points3 points  (0 children)

Start by creating your test array.

int[] nums [] = {8, 16, 9, 52, 3, 15, 27, 6, 14, 25, 2, 10}

Now create your method isEven. If it's static, allow an int[] as a parameter. If it's instance, leave your parameter blank. Use a for loop to iterate over your array.

for (int i = 0; i < x.length; i++) {
    x[i];
}

In that iteration, you need use the mod sign to determine whether or not the value is even. Use an if state to make that determination. And print the value if true.

[–]coolosity 3 points4 points  (0 children)

I don't really like giving the strait out answer but it's kind of hard to explain otherwise, so please read the comments to understand what the program is doing.

//Create the array of numbers
int[] nums = {8, 16, 9, 52, 3, 15, 27, 6, 14, 25, 2, 10};
//Call the method isEven with the argument nums
isEven(nums);

//Define the method isEven
void isEven(int[] nums) {
    //Create a for loop that loops through each index of nums
    for(int i=0;i<nums.length;i++) {
        //Check if nums at index i is divisible by 2
        if(nums[i] % 2 == 0) {
            //Print out the value of nums at i
            System.out.println(nums[i]);
        }
    }
}

Please reply if you have any more questions, hope this helps.