Array Summation

Easy2s max execution

Implement a method that calculates the sum of all elements in an array of integers.

📝 Requirements:

  1. Input constraints:
    • The array numbers contains only integers
    • The array always contains at least one element
    • The array will never contain more than 10 elements
  2. Value constraints:
    • All integers are between -10,000 and 10,000

💡 Example:

For the array [5, 10, 15, 20]:

  • The sum is 5 + 10 + 15 + 20 = 50
  • Return value should be 50

🎯 Your Task:

Complete the calculateSum method that takes an array of integers and returns the sum of all elements in the array.

Examples:

Input: [5, 10, 15, 20]
Output: 50

5 + 10 + 15 + 20 = 50

Input: [-5, 5]
Output: 0

-5 + 5 = 0

Input: [42]
Output: 42

When there's only one number, it's the sum by itself

Constraints:

  • 1 ≤ numbers.length ≤ 10
  • -10,000 ≤ numbers[i] ≤ 10,000
  • Array contains at least one element
  • All numbers are integers
Standard imports available:java.util.*, java.io.*, java.math.*, etc.
Loading...

Custom Test Input

Output

Run your code to see output...