-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_2_student_grade_calculator.java
44 lines (35 loc) · 1.46 KB
/
task_2_student_grade_calculator.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
39
40
41
42
43
44
import java.util.Scanner;
public class task_2_student_grade_calculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the total number of subjects: ");
int numOfSubjects = scanner.nextInt();
int total_Marks = 0;
for (int i = 1; i <= numOfSubjects; i++) {
System.out.print("Enterthe marks obtained in subject-" + i + " out of 100: ");
int marks = scanner.nextInt();
total_Marks += marks;
}
double avg_Percentage = (double) total_Marks / numOfSubjects;
String grade;
if (avg_Percentage >= 95) {
grade = "A+";
} else if (avg_Percentage >= 85) {
grade = "A";
} else if (avg_Percentage >= 75) {
grade = "B";
} else if (avg_Percentage >= 60) {
grade = "C";
} else if (avg_Percentage >= 45) {
grade = "D";
} else if (avg_Percentage >= 35) {
grade = "E";
} else {
grade = "Fail";
}
System.out.println("\nTotal Marks: " + total_Marks);
System.out.println("Average Percentage: " + avg_Percentage + "%");
System.out.println("Grade: " + grade);
scanner.close();
}
}