JAVA · ОСНОВЫ · LESSON 15
Put the whole row together.
Array and sum · about 16 minutes
Learning with progressRead the summary for free. To save the work, log in to the account.
Type the code yourself
Type an example manually. Check the signs and brackets.
public class Main {
public static void main(String[] args) {
int[] nums = {2, 3};
int total = 0;
for (int number : nums) {
total += number;
}
System.out.println(total);
}
}Open the editor for class workSolve it yourself
Create int[] nums from 1, 2, 3. Start with int total = 0, add each number using for-each and output total.
The answer is hidden. Use similar examples from the lesson notes.
Opening up your homework