-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTUDENTGRADECALCULATOR.java
More file actions
52 lines (51 loc) · 1.5 KB
/
Copy pathSTUDENTGRADECALCULATOR.java
File metadata and controls
52 lines (51 loc) · 1.5 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
import java.util.Scanner;
public class STUDENTGRADECALCULATOR
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number of subjects:");
int numSubjects = scanner.nextInt();
int totalMarks = 0;
for (int i = 1; i <= numSubjects; i++)
{
System.out.println("Enter marks for Subject " + i + ":");
int subjectMarks = scanner.nextInt();
if (subjectMarks < 0 || subjectMarks > 100)
{
System.out.println("Invalid marks! Marks should be between 0 and 100.");
return;
}
totalMarks += subjectMarks;
}
double averagePercentage = (double) totalMarks / numSubjects;
System.out.println("Total Marks: " + totalMarks);
System.out.println("Average Percentage: " + averagePercentage + "%");
String grade = calculateGrade(averagePercentage);
System.out.println("Grade: " + grade);
scanner.close();
}
private static String calculateGrade(double averagePercentage)
{
if (averagePercentage >= 90)
{
return "A";
}
else if (averagePercentage >= 80)
{
return "B";
}
else if (averagePercentage >= 70)
{
return "C";
}
else if (averagePercentage >= 60)
{
return "D";
}
else
{
return "F";
}
}
}