-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCGPA.java
30 lines (23 loc) · 954 Bytes
/
CGPA.java
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
package solutions;
// Q: Calculate CGPA java program
import java.util.Scanner;
public class CGPA {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// Prompt the user for number of semesters
System.out.print("Enter the toal number of semesters you had: ");
int sem = in.nextInt();
// Ask for the percentage of individual semesters
System.out.println("Enter the percentage of each semesters respectively(For eg. 95 for 95%):");
float totalpercentage = 0;
for (int i = 0; i < sem; i++) {
System.out.print("Semester " + (i + 1) + " percentage: ");
float percentage = in.nextFloat();
totalpercentage += percentage;
}
// calculate CGPA
float cgpa = (float) ((totalpercentage / sem) / 9.5);
// Display the cgpa
System.out.println("CGPA = " + String.format("%.2f", cgpa));
}
}