Write a program in Java to calculate average marks
Answers
Answered by
2
Answer:
import java.util.Scanner;
class AverageCalculation
{
double avg=0;
AverageCalculation(int a[])
{
for(int i=0;i<a.length;i++)
{
avg=avg+a[i];
}
}
}
class AverageMarks
{
public static void main(String args[])
{
int i;
System.out.println("Enter number of subjects");
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] a=new int[n];
System.out.println("Enter marks");
for( i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
AverageCalculation c=new AverageCalculation(a);
System.out.print("Average of (");
for(i=0;i<n-1;i++)
{
System.out.print(a[i]+",");
}
System.out.println(a[i]+") ="+c.avg/n);
Explanation:
Similar questions