Answer to Question #289156 in Java | JSP | JSF for Marks

Question #289156

Write a program to create a single dimension array to store marks of 25 students. Then display the highest mark and also display how many students got the same highest mark.


import java.util.*;

class Marks {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

int a[] = new int[25];

int i; //loop

int j, d; //swapping elements sorting

int c=0; //To frequency

System.out.println("Enter marks of 25 students");

for (i = 0; i < 25; i++) {

a[i] = sc.nextInt();

}

// Stored 25 marks in an array

for (i = 0; i < 24; i++) {

for (j = 0; j < 24 - i; j++) {

if (a[j] < a[j + 1]) {

d = a[j];

a[j] = a[j + 1];

a[j + 1] = d;

// Elements swapped in descending order

}

}

}

Continue from here to: Find the highest marks and frequency of those students.


1
Expert's answer
2022-01-20T08:27:48-0500
import java.util.*;


class Marks {


	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a[] = new int[25];
		int i; // loop
		int j, d; // swapping elements sorting
		int c = 0; // To frequency
		System.out.println("Enter marks of 25 students");
		for (i = 0; i < 25; i++) {
			a[i] = sc.nextInt();
		}


		// Stored 25 marks in an array
		for (i = 0; i < 24; i++) {
			for (j = 0; j < 24 - i; j++) {
				if (a[j] < a[j + 1]) {
					d = a[j];
					a[j] = a[j + 1];
					a[j + 1] = d;
					// Elements swapped in descending order
				}
			}
		}
		// the highest marks and frequency of those students.
		for (i = 0; i < 24; i++) {
			if (a[0] == a[i]) {
				c++;
			}
		}
		System.out.println("The highest mark: " + a[0]);
		System.out.println(c + " students got the same highest mark.");


	}
}

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