# Java Program to illustrate Total Marks and Percentage Calculation

• Last Updated : 09 Nov, 2020

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)

My Personal Notes arrow_drop_up