-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentGradeCalculator.java
More file actions
49 lines (40 loc) · 1.51 KB
/
Copy pathStudentGradeCalculator.java
File metadata and controls
49 lines (40 loc) · 1.51 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Scanner;
public class StudentGradeCalculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Input number of subjects
System.out.print("Enter the number of subjects: ");
int numOfSubjects = sc.nextInt();
// Input marks obtained in each subject
int[] marks = new int[numOfSubjects];
int totalMarks = 0;
for (int i = 0; i < numOfSubjects; i++) {
System.out.print("Enter marks obtained in subject " + (i + 1) + ": ");
marks[i] = sc.nextInt();
totalMarks += marks[i];
}
// Calculate total marks
System.out.println("Total Marks: " + totalMarks);
// Calculate average percentage
double avgPercentage = (double) totalMarks / numOfSubjects;
System.out.printf("Average Percentage: %.2f \n", avgPercentage);
// Grade Calculation
char grade;
if (avgPercentage >= 90) {
grade = 'A';
} else if (avgPercentage >= 80) {
grade = 'B';
} else if (avgPercentage >= 70) {
grade = 'C';
} else if (avgPercentage >= 60) {
grade = 'D';
} else if (avgPercentage >= 50) {
grade = 'E';
} else {
grade = 'F';
}
// Display Results
System.out.println("Grade: " + grade);
sc.close();
}
}