Statistics

Problem Statement for "OddSum"

Problem Statement

You are given a int[] x. Find the sum of all the odd integers in x.

Definition

Class:
OddSum
Method:
getSum
Parameters:
int[]
Returns:
int
Method signature:
int getSum(int[] x)
(be sure your method is public)

Constraints

  • x will contain between 1 and 50 elements, inclusive.
  • Each element of x will be between 0 and 100, inclusive.

Examples

  1. { 1, 2, 3 }

    Returns: 4

    Here, we want to include 1 and 3, but not 2. 1 + 3 = 4

  2. { 2, 4, 6 }

    Returns: 0

    Here there are no odd elements at all, so our sum is 0.

  3. { 8, 3, 3, 4 }

    Returns: 6

    Elements are not necessarily unique, and not necessarily sorted.

  4. { 73, 82, 16, 47 }

    Returns: 120

  5. { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }

    Returns: 25

  6. {8, 3, 3, 4 }

    Returns: 6


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: