-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask2
38 lines (31 loc) · 1.09 KB
/
task2
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
import java.util.Scanner;
public class Task2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of subjects: ");
int numSubjects = scanner.nextInt();
int totalMarks = 0;
for (int i = 1; i <= numSubjects; i++) {
System.out.print("Enter marks for subject " + i + ": ");
int marks = scanner.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("Total Marks: " + totalMarks);
System.out.println("Average Percentage: " + averagePercentage + "%");
System.out.println("Grade: " + grade);
scanner.close();
}
}