import java.util.Scanner; public class CGPACalculator { // Method to calculate CGPA based on grades public static double calculateCGPA(int[] grades, int numSubjects) { double totalGradePoints = 0.0; // Grade points based on some common grading scale for (int i = 0; i < numSubjects; i++) { int grade = grades[i]; if (grade >= 90) { totalGradePoints += 10; // A+ } else if (grade >= 80) { totalGradePoints += 9; // A } else if (grade >= 70) { totalGradePoints += 8; // B+ } else if (grade >= 60) { totalGradePoints += 7; // B } else if (grade >= 50) { totalGradePoints += 6; // C+ } else if (grade >= 40) { totalGradePoints += 5; // C } else { totalGradePoints += 0; // F } } // CGPA is the average of grade points return totalGradePoints / numSubjects; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // Get the number of subjects System.out.print("Enter the number of subjects: "); int numSubjects = scanner.nextInt(); // Create an array to store the grades int[] grades = new int[numSubjects]; // Get grades from the user for (int i = 0; i < numSubjects; i++) { System.out.print("Enter marks for subject " + (i + 1) + ": "); grades[i] = scanner.nextInt(); } // Calculate the CGPA double cgpa = calculateCGPA(grades, numSubjects); // Output the CGPA System.out.println("Your CGPA is: " + cgpa); scanner.close(); } }