-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram46.java
More file actions
30 lines (24 loc) · 969 Bytes
/
Program46.java
File metadata and controls
30 lines (24 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
class CGPAPercentageCalculator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of Subject: ");
int numCourses = input.nextInt();
double totalCGPA = 0.0;
double totalCredits = 0.0;
for (int i = 1; i <= numCourses; i++) {
System.out.printf("Enter CGPA for Subject %d: ", i);
double cgpa = input.nextDouble();
System.out.printf("Enter Credits for Subject %d: ", i);
int credits = input.nextInt();
totalCGPA += cgpa * credits;
totalCredits += credits;
}
if (totalCredits == 0) {
System.out.println("Error: Total credits cannot be zero.");
} else {
double cgpaPercentage = (totalCGPA / totalCredits) * 10;
System.out.printf("CGPA Percentage: %.2f%%\n", cgpaPercentage);
}
}
}