Java Program to Calculate Average and Percentage Marks

Here is a Java program to find the total, average and percentage marks of all subjects. In this java program, We will first take the number of subjects as input and store it in "count" variable. Then we ask user to enter the marks of all subjects using for loop. To get the total marks obtained by student we add the marks of all subject and to calculate average marks and percentage we will use following expression:

Average Marks = Marks_Obtained/Number_Of_Subjects
Percentage of Marks = (Marks_Obtained/Total_Marks) X 100

Finally, we print Total marks, Average Marks and Percentage on screen.

Java program to find total, average and percentage marks all subjects


import java.util.Scanner;

public class AverageMarks {
    public static void main(String[] args) {
        int count, i;
        float totalMarks = 0, percentage, average;
        Scanner scanner;
        scanner = new Scanner(;

        System.out.println("Enter number of Subject");
        count = scanner.nextInt();

        System.out.println("Enter Marks of " + count 
            + " Subject");
        for (i = 0; i < count; i++) {
            totalMarks += scanner.nextInt();

        average = totalMarks / count;
        // Each subject is of 100 Marks
        percentage = (totalMarks / (count * 100)) * 100;

        System.out.println("Total Marks : " + totalMarks);
        System.out.println("Average Marks : " + average);
        System.out.println("Percentage : " + percentage);
Enter number of Subject
Enter Marks of 5 Subject
75 86 92 46 60
Total Marks : 359.0
Average Marks : 71.8
Percentage : 71.8

Recommended Posts
Java Program to Calculate Grade of Students
Java Program to Find LCM and GCD of Two Numbers
Java Program to Calculate Arithmetic Mean of N Numbers
Java Program to Find Area of Right Angled Triangle
Java Program to Find Sum of all Odd Numbers between 0 to N
Java Program to Check Whether a Number is Palindrome or Not
Java Program to Find Largest of Three Numbers
Java Program to Find Average of all Array Elements
Java Program to Find Sum of Elements of an Array
Java Program to Find Largest and Smallest Number in an Array
Java program to convert binary number to decimal number
All Java Programs