Write the pseudocode for the following scenario. The final exam marks for 10 students
are 65, 45, 78, 65, 89, 65, 79, 67, 75, and 63. The marks are stored in an array. Find:
• The student with the highest mark.
• The student with the lowest mark.
• The total marks for all the students.
• The overall average.
public class Main {
public static void main(String[] args) {
int[] marks = {65, 45, 78, 65, 89, 65, 79, 67, 75, 63};
int maxMark = 0, minMark = marks[0], sumMarks = 0;
double middleMark;
for (int a:marks) {
if(maxMark < a){
maxMark = a;
}
if(minMark > a){
minMark = a;
}
sumMarks += a;
}
middleMark = (double) sumMarks / 2;
System.out.print( "The student with the highest mark: " + maxMark +
"\nThe student with the lowest mark: " + minMark +
"\nThe total marks for all the students: " + sumMarks +
"\nThe overall average: " + middleMark);
}
}
Comments
Leave a comment