sumOfMarks is used to store the sum of the marks entered.
In a for loop which runs for 10 times, the marks are taken as input and added to sumOfMarks.
Average is calculated by dividing sumOfMarks by 10.0 (not 10. If you divide by 10, you won’t get the digits after decimal point)
import java.util.Scanner;
public class Multiples {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int sumOfMarks = 0;
System.out.println("Enter marks of 10 students: ");
for (int i = 0; i < 10; i++) {
int marks = scanner.nextInt();
sumOfMarks = sumOfMarks + marks;
}
double average = sumOfMarks / 10.0;
System.out.println("Average = " + average);
}
}
Sample Output
Enter marks of 10 students:
90
85
99
98
97
82
80
90
99
95
Average = 91.5