-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentGradingSystem.java
38 lines (32 loc) · 1.1 KB
/
StudentGradingSystem.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
30
31
32
33
34
35
36
37
38
import java.util.Scanner;
public class StudentGradingSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of students: ");
int numberOfStudents = scanner.nextInt();
int[] studentMarks = new int[numberOfStudents];
for (int i = 0; i < numberOfStudents; i++) {
System.out.println("Enter marks for student " + (i + 1) + ": ");
studentMarks[i] = scanner.nextInt();
}
// Close the scanner to prevent resource leak
scanner.close();
for (int marks : studentMarks) {
char grade = calculateGrade(marks);
System.out.println("Student with marks " + marks + " gets grade: " + grade);
}
}
public static char calculateGrade(int marks) {
if (marks >= 90) {
return 'A';
} else if (marks >= 80) {
return 'B';
} else if (marks >= 70) {
return 'C';
} else if (marks >= 60) {
return 'D';
} else {
return 'F';
}
}
}