-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
60 lines (45 loc) · 1.82 KB
/
Main.java
File metadata and controls
60 lines (45 loc) · 1.82 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 Task_2;
//STUDENT GRADE CALCULATOR
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Create a Scanner object to read user input
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter the number of subjects
System.out.println("Enter the number of subjects: ");
int numberOfSubjects = scanner.nextInt();
// Create an array to store the marks obtained in each subject
int[] marks = new int[numberOfSubjects];
// Prompt the user to enter the marks obtained in each subject
for (int i = 0; i < numberOfSubjects; i++) {
System.out.println("Enter the marks obtained out of 100 in subject " + (i + 1) + ": ");
marks[i] = scanner.nextInt();
}
// Calculate the total marks
int totalMarks = 0;
for (int mark : marks) {
totalMarks += mark;
}
// Calculate the average percentage
float averagePercentage = (float) totalMarks / numberOfSubjects;
// Assign a grade based on the average percentage
String 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";
}
// Display the results
System.out.println("Total marks: " + totalMarks+"/"+(numberOfSubjects*100));
System.out.println("Average percentage: " + averagePercentage);
System.out.println("Grade: " + grade);
// Close the Scanner object
scanner.close();
}
}