# Java program to calculate average marks

In this post, we will see how to calculate average marks in java.

## Problem

Given the marks of n subject as array, calculate average and percentage of Student.

Example:

arr[] = {92,67,87,98,89,74};

Average Marks = 84.5

Percentage = 84.5%

arr[] = {92,67,87,98,89,74};

Average Marks = 84.5

Percentage = 84.5%

## Solution

- Formula for average = sum of marks /total number of subjects
- Percentage = (sum of marks/total marks) * 100

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
package org.arpit.code2master; public class AveragePercentageCalcJava { public static void main(String args[]) { int arr[] = {92,67,87,98,89,74}; int n=arr.length; double sum=0; double average, percentage; for (int i = 0; i < arr.length; i++) { sum+=arr[i]; } System.out.println(sum); average = sum/n; percentage = (sum/(n*100)) * 100; System.out.println("Average Marks = " +average); System.out.println("========================"); System.out.print("Percentage = " +percentage+ "%"); } } |

Output:

Average Marks = 84.5

========================

Percentage = 84.5%

========================

Percentage = 84.5%