-
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.59 KB
/
StudentGradeCalculator.java
File metadata and controls
50 lines (41 loc) · 1.59 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 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Grade Calculator");
System.out.print("Enter the number of subjects: ");
int numSubjects = scanner.nextInt();
int[] marks = new int[numSubjects];
int totalMarks = 0;
for (int i = 0; i < numSubjects; i++) {
System.out.print("Enter marks for Subject " + (i + 1) + " (out of 100): ");
marks[i] = scanner.nextInt();
if (marks[i] < 0 || marks[i] > 100) {
System.out.println("Invalid marks. Please enter a value between 0 and 100.");
i--;
continue;
}
totalMarks += marks[i];
}
double averagePercentage = (double) totalMarks / numSubjects;
String grade;
if (averagePercentage >= 90) {
grade = "A+";
} else if (averagePercentage >= 80) {
grade = "A";
} else if (averagePercentage >= 70) {
grade = "B";
} else if (averagePercentage >= 60) {
grade = "C";
} else if (averagePercentage >= 50) {
grade = "D";
} else {
grade = "F";
}
System.out.println("\n Results:");
System.out.println("Total Marks: " + totalMarks);
System.out.printf("Average Percentage: %.2f%%\n", averagePercentage);
System.out.println("Grade: " + grade);
scanner.close();
}
}