-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentGradeCalculator
More file actions
44 lines (41 loc) · 1.46 KB
/
StudentGradeCalculator
File metadata and controls
44 lines (41 loc) · 1.46 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
import java. util.Scanner;
public class StudentGradeCalculator{
public static void main(String[] args){
Scanner scanner= new Scanner(System.in);
System.out.println("Enter the no of subjects:");
int numSubjects=scanner.nextInt();
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();
if(marks< 0 || marks>100){
System.out.println("Invalid marks. ");
i--;
continue;
}
totalMarks +=marks;
}
double averagePercentage = (double)totalMarks/ numSubjects;
String grade= calculateGrade(averagePercentage);
System.out.println("\nResults:");
System.out.println("TotalMarks:" + totalMarks);
System.out.printf("Average Percentage: %.2f%%\n", averagePercentage);
System.out.println("Grade: " + grade);
scanner.close();
}
public static String calculateGrade(double averagePercentage) {
if (averagePercentage >= 90) {
return "A+";
} else if (averagePercentage >= 80) {
return "A";
} else if (averagePercentage >= 70) {
return "B";
} else if (averagePercentage >= 60) {
return "C";
} else if (averagePercentage >= 50) {
return "D";
} else {
return "F";
}
}
}