Java program to Finding Average marks of given array

Problem statement:- write a program in java to find a average marks of given array

package Loops;

import java.util.Scanner;

public class average {

    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        System.out.print("enter the number: ");
        int n=sc.nextInt();
        double marks[]=new double[n];
        double averagemarks=0;
        for(int i=0;i<n;i++) {
            marks[i]=sc.nextDouble();
            averagemarks+=marks[i];
          }
        averagemarks/=n;
        System.out.println("the average of marks is " +averagemarks);
    }
}
output:-
enter the number: 5
1
74
4
6
3
the average of marks is 17.6

Comments