-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp46.java
29 lines (23 loc) · 853 Bytes
/
p46.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
public class p46 {
public static void main(String[] args) {
int n=4;
int[] grades = new int[n];
System.out.println(" Total subject on your Course:"+n);
int total = 0;
for (int i = 0; i < n; i++) {
System.out.println("Grade of subject " + (i + 1) + ":");
java.util.Scanner sc=new java.util.Scanner(System.in);
grades[i] = sc.nextInt();
if (grades[i] >= 0 && grades[i] <= 10) {
total += grades[i];
} else {
System.out.println("Invalid grade. Please enter a number between 0 and 10");
i--;
}
}
double cgpa = (double) total / n;
double p = cgpa * 9.5;
System.out.println("Your CGPA is: " + cgpa);
System.out.println("Your percentage is: " + p + "%");
}
}