public class Main { public static void main(String[] args) { int [] scores = {20, 30, 40, 50, 80}; int sum = 0; // Aggregation result for (int i = 0; i < scores.length; i++) { sum + = scores [i]; // Sum to the variable sum }
int avg = sum / scores.length;
System.out.println ("total score:" + sum); System.out.println ("average score:" + avg);
}
}
Recommended Posts