X1498: Odd Number Counter

Problem Description

Write a method countOdds that takes an array of integers and returns the count of values that are odd numbers.

public int countOdds(int[] arr)

Requirements

  • An odd number is any integer not divisible by 2 (i.e., num % 2 != 0).
  • You should iterate through the array and count how many numbers are odd.

Constraints

  • The array will contain at least one integer.
  • The array may include negative numbers.

Examples:

countOdds({2, 3, 5, 6, 8, 9}) -> 3
countOdds({11}) -> 1
countOdds({12}) -> 0

Your Answer:

Feedback

Your feedback will appear here when you check your answer.