Computer Science, asked by shrutixyzreena1111, 2 days ago

.A program to calculate average marks of n students using list manipulation function where n is entered by the user. ​

Answers

Answered by samarthkrv
1

Answer:

import java.util.*;

class Average {

   public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

 ArrayList<Integer> students = new ArrayList<Integer>();

 int total = 0;

 double avg;

 System.out.print("Enter the number of students:");

 int n = sc.nextInt();

     for(int i = 0; i < n; i++){

         System.out.print("Enter the marks of student " + (i+1) + ":");

         int x = sc.nextInt();

         students.add(x);

         total = total + students.get(i);

     }

     avg = total/n;

     System.out.println("The average marks of " + n + " students is " + avg);

   }

}

Explanation:

Similar questions