-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentGradeCalculator.java
More file actions
60 lines (46 loc) · 1.43 KB
/
StudentGradeCalculator.java
File metadata and controls
60 lines (46 loc) · 1.43 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
51
52
53
54
55
56
57
58
59
60
package Java_CodSoft;
import java.util.Scanner;
public class StudentGradeCalculator{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of the subjects: ");
int numSubjects = sc.nextInt();
int totalMarks = 0;
System.out.println("Enter marks obtained in each subject (out of 100):");
for(int i = 1; i <= numSubjects; i++){
System.out.print("Subject " + i + ": ");
int marks = sc.nextInt();
totalMarks += marks;
}
double averagePercentage = (double)totalMarks / numSubjects;
char grade;
if (averagePercentage >= 90){
grade = 'A';
} else if (averagePercentage >= 80){
grade = 'B';
} else if (averagePercentage >= 70){
grade = 'C';
} else if (averagePercentage >= 60){
grade = 'D';
} else {
grade = 'F';
}
System.out.println("\nResults:");
System.out.println("Total Marks : " + totalMarks);
System.out.println("Average Percentage: " + averagePercentage);
System.out.println("Grade: " + grade);
sc.close();
}
}
/*
Enter the number of subjects: 5
Enter marks obtained in each subject (out of 100):
Subject 1: 99
Subject 2: 99
Subject 3: 99
Subject 4: 96
Subject 5: 100
Results:
Total Marks: 493
Average Percentage: 98.6
Grade: A*/