Miscellaneous
Java Program to Calculate CGPA
A Java program to calculate CGPA.
Problem Description
Write a Java program to calculate CGPA (Cumulative Grade Point Average).
Code
public class CalculateCGPA {
public static void main(String[] args) {
int n = 5;
double[] marks = { 90, 80, 70, 80, 90 };
double[] grade = new double[n];
double cgpa, sum = 0;
for (int i = 0; i < n; i++) {
grade[i] = (marks[i] / 10);
}
for (int i = 0; i < n; i++) {
sum += grade[i];
}
cgpa = sum / n;
System.out.println("CGPA = " + cgpa);
System.out.println("Percentage from CGPA = " + cgpa * 9.5);
}
}Output
CGPA = 8.2
Percentage from CGPA = 77.9Explanation
- Grade: Divide marks by 10 to get grade points.
- CGPA: Average of grade points.
