Sum of N Numbers
Easyjava
Read a count N, then read N integers, and print their sum.
Input: the first token is N; then N integers (any whitespace between them).
Output: one line — the sum of the N integers.
Example 1
Input
3 10 20 30
Output
60
- 1 <= N <= 1000
- -1000000 <= each integer <= 1000000
Hint 1
Scanner ignores the difference between spaces and newlines for nextInt().
Hint 2
Loop exactly n times.
nextInt() skips any whitespace (spaces or newlines) before each number, so the same loop works no matter how the N values are laid out. Accumulate them into a long sum.