TopcoderARCHIVE
SRM · Problem 17398

OddSum

Problem statement, definition, constraints, and public examples.

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
← All problems