JAVA · ОСНОВЫ · LESSON 25
Final project: points
Array, loop, condition and method · about 20 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[] scores = {2, 3, 4};
int total = sum(scores);
System.out.println(total);
if (total >= 8) {
System.out.println("Победа");
}
}
static int sum(int[] scores) {
int total = 0;
for (int score : scores) {
total += score;
}
return total;
}
}Open the editor for class workSolve it yourself
Do the final program: int[] scores of 1, 2, 5; static int sum(Zint[] scores) folds them through for-each and returns the amount. In main, output total and, if total is at least 8, output «Готово».
The answer is hidden. Use similar examples from the lesson notes.
Opening up your homework