Open In App

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 : 

Below are the examples of the above approach.






// 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)

Article Tags :