Thursday, February 19, 2026
HomeLanguagesJavaJava Program to illustrate Total Marks and Percentage Calculation

Java Program to illustrate Total Marks and Percentage Calculation

Java Program to illustrate Total marks and Percentage Calculation can be done using storing marks of all subjects in an array and taking the summation of marks of all subjects and taking the average of all marks respectively.

Example

Input: N = 5, marks[] = {70, 60, 90, 40, 80}
Output: Total Marks = 340
        Total Percentage = 68%
        
Input: N = 5, marks[] = {60, 70, 80, 90, 100}
Output: Total Marks = 400
        Total Percentage = 80%

Approach : 

  • Enter the number of subjects N and marks of those subjects into a 1-D array, say, marks[].
  • Create a variable total_marks which stores the total of all the marks.
  • To print the percentage of that student, divide total_marks with N.

Below are the examples of the above approach.

Java




// Java Program to illustrate Total
// marks and Percentage Calculation
import java.io.*;
class GFG {
    public static void main(String[] args)
    {
        int N = 5, total_marks = 0;
        float percentage;
  
        // create 1-D array to store marks
        int marks[] = { 89, 75, 82, 60, 95 };
  
        // calculate total marks
        for (int i = 0; i < N; i++) {
            total_marks += marks[i];
        }
        System.out.println("Total Marks : " + total_marks);
  
        // calculate percentage
        percentage = (total_marks / (float)N);
        System.out.println(
            "Total Percentage : " + percentage + "%");
    }
}


Output

Total Marks : 401
Total Percentage : 80.2%

Time Complexity: O(N)

Space Complexity: O(1)

RELATED ARTICLES

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS