0% found this document useful (0 votes)
137 views

Grade

This Java code defines a method that calculates student grades based on their marks. It takes in a 2D array of student marks, calculates the average mark for each student by summing all their marks and dividing by the number of marks, then assigns a letter grade based on the average ranging from A+ to F depending on where the average falls in ranges from 90-100, 80-89, 70-79, etc. It returns an array containing the grade for each student.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views

Grade

This Java code defines a method that calculates student grades based on their marks. It takes in a 2D array of student marks, calculates the average mark for each student by summing all their marks and dividing by the number of marks, then assigns a letter grade based on the average ranging from A+ to F depending on where the average falls in ranges from 90-100, 80-89, 70-79, etc. It returns an array containing the grade for each student.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

class Result {

public static String[] calculateGrade(int[][] students_marks) {


String[] grade = new String[students_marks.length];
int avg=0;
int sum=0;
for (int i = 0; i < students_marks.length; i++) {
for (int j = 0; j < students_marks.length; j++) {
sum = students_marks[i][j];
}
}

for(int x=0;x<students_marks.length;x++){
avg = (sum/students_marks[x].length);
if(avg >= 90)
grade[x] = "A+";
else if(avg>=80 && avg<90)
grade[x] = "A";
else if(avg>=70 && avg<80)
grade[x] = "B";
else if(avg>=60 && avg<70)
grade[x] = "C";
else if(avg>=50 && avg<60)
grade[x] = "D";
else if (avg < 50);
grade[x] = "F";
}
return grade;
}
}

You might also like