← Java from Scratch Lesson 20 of 88 · 5 XP

Warm-up: sum of numbers warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

You can add numbers up while reading them — into a piggy-bank variable:

int n = in.nextInt();
int sum = 0;
for (int i = 0; i < n; i++) {
    sum += in.nextInt();
}

Task. Read n, then n integers, and print their sum.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.