-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentGradeCalculator.java
More file actions
50 lines (41 loc) · 1.51 KB
/
Copy pathStudentGradeCalculator.java
File metadata and controls
50 lines (41 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
50
import java.util.Scanner;
public class StudentGradeCalculator {
@SuppressWarnings("ConvertToTryWithResources")
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
// Input: Number of subjects
System.out.print("Enter the number of subjects: ");
int numSubjects = s.nextInt();
// Array to store marks for each subject
int[] marks = new int[numSubjects];
int totalMarks = 0;
// Input: Marks for each subject
System.out.println("Enter marks obtained (out of 100) for each subject:");
for (int i = 0; i < numSubjects; i++) {
System.out.print("Subject " + (i + 1) + ": ");
marks[i] = s.nextInt();
totalMarks += marks[i];
}
// Calculate average percentage
double averagePercentage = (double) totalMarks / numSubjects;
// Determine grade
char grade;
if (averagePercentage >= 90) {
grade = 'A';
} else if (averagePercentage >= 80) {
grade = 'B';
} else if (averagePercentage >= 70) {
grade = 'C';
} else if (averagePercentage >= 60) {
grade = 'D';
} else {
grade = 'F';
}
// Display results
System.out.println("\nResults:");
System.out.println("Total Marks: " + totalMarks);
System.out.println("Average Percentage: " + averagePercentage + "%");
System.out.println("Grade: " + grade);
s.close();
}
}