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