-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradeCalculator.java
More file actions
29 lines (23 loc) · 806 Bytes
/
GradeCalculator.java
File metadata and controls
29 lines (23 loc) · 806 Bytes
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
import java.util.*;
public class GradeCalculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of subjects: ");
int n = sc.nextInt();
int total = 0;
for (int i = 1; i <= n; i++) {
System.out.print("Enter marks of subject " + i + ": ");
total += sc.nextInt();
}
double avg = total / (double) n;
char grade;
if (avg >= 90) grade = 'A';
else if (avg >= 80) grade = 'B';
else if (avg >= 70) grade = 'C';
else if (avg >= 60) grade = 'D';
else grade = 'F';
System.out.println("Total = " + total);
System.out.println("Average = " + avg);
System.out.println("Grade = " + grade);
}
}