-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask2.java
51 lines (38 loc) · 1.41 KB
/
Task2.java
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
// Task 2: Student Grade Calculator
import java.util.Scanner;
public class Task2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Hello,Enter the Number of Subjects: ");
int numSubjects = scanner.nextInt();
int[] marks = new int[numSubjects];
int totalMarks = 0;
for (int i = 0; i < numSubjects; i++) {
System.out.print("Enter marks obtained in each Subject " + (i + 1) + ": ");
marks[i] = scanner.nextInt();
totalMarks += marks[i];
}
double averagePercentage = (double) totalMarks / (numSubjects * 100) * 100;
System.out.println("Your Result is Here:");
System.out.println("Your Total Marks: " + totalMarks);
System.out.println("Average Percentage: " + averagePercentage + "%");
String grade = calculateGrade(averagePercentage);
System.out.println("Grade: " + grade);
scanner.close();
}
public static String calculateGrade(double percentage){
if (percentage >= 90) {
return "A+";
} else if (percentage >= 80) {
return "A";
} else if (percentage >= 70) {
return "B";
} else if (percentage >= 60) {
return "C";
} else if (percentage >= 50) {
return "D";
} else {
return "F";
}
}
}