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
import java.io.*;
class GFG {
public static void main(String[] args)
{
int N = 5 , total_marks = 0 ;
float percentage;
int marks[] = { 89 , 75 , 82 , 60 , 95 };
for ( int i = 0 ; i < N; i++) {
total_marks += marks[i];
}
System.out.println( "Total Marks : " + total_marks);
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)
Last Updated :
09 Nov, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...