Answer to Question #247029 in Java | JSP | JSF for maria

Question #247029

consider an array MARKS [20] [5] which stores the marks obtained by 20 students in 5 subjects. now write a program.

(a.) find the average marks obtained in each subject.

(b.)find the average marks obtained by every student

(c.) find the number of students who have scored below 50 in their average.

(d.) display the scores obtained by every student.


1
Expert's answer
2021-10-05T18:15:49-0400


package studentmarks;




public class StudentMarks {


    
    public static void main(String[] args) {
        
       int [][]  MARKS = {{48,27,10,67,18}, {58,89,40,80,78},{47,40,49,78,40},{69,40,89,88,67},
                        {38,91,76,34,67},{66,45,89,34,90}, {97,78,90,67,56},{57,78,90,87,76},
                        {77,98,50,57,46}, {57,98,70,67,86}, {77,68,70,67,56}, {97,98,90,67,56},
                        {67,78,90,67,56}, {27,48,60,87,56},{17,58,90,97,86}, {67,78,90,67,56},
                        {37,58,90,67,56}, {77,78,70,67,66}, {67,78,90,67,56}, {97,88,90,67,76}};
       
       float total = 0;
float average = 0;
//Part a
System.out.println("Average marks for each subject\n");
System.out.println("Subject     \tAverage\n");
int [] student = new int [100];
int n  = 0;
for(int i=0; i<20; i++){
    for(int j=0; j<5; j++){
        student[n++] = MARKS[i][j];
    }
}
int [][] marks = new int[5][20];
int k = 0;
for(int i=0; i<5; i++){
    for(int j=0; j<20; j++){
        marks[i][j] = student[k++];
    }
}












for (int i = 0; i < 5; i++)
{
   for (int j = 0; j < 20; j++)
   {
       total += marks[i][j];
   }
   average = total/20;
 System.out.printf("%d\t\t %f\n", (i+1), average);
   
   
   average = 0;
   total = 0;
}
int count =0;
double [] averageScore = new double[20];
//Part b Answer
System.out.println("Average marks for every student\n");
System.out.println("Student     \tAverage\n");


for(int i=0; i<20; i++){
	float sum = 0;
	for(int j=0; j<5; j++){
		sum +=  MARKS[i][j];
	}
        System.out.printf("%d     \t\t%f\n", (i+1), (sum / 5 ));
	
	averageScore[i] = sum / 5;
}
for(int i=0; i<20; i++){
if(averageScore[i]<50){
	count++;
}
}
//Part (c) answer
System.out.printf("The number of students with average less than 50: %d\t", count);


//Part (d) answer
System.out.printf("Average marks obtained by every student\n");
System.out.printf("Student     \tScores\n");




for(int i=0; i<20; i++){
    System.out.printf("%d:   \t\t  %f \n", (i+1), (averageScore[i] * 5 ));
	
}


}
    
    
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS