Answer to Question #286806 in Java | JSP | JSF for ____

Question #286806

Write a program in Java to create two SDA to store names and marks of 25 students then display the name of the students as per their marks in descending order.

1
Expert's answer
2022-01-12T05:07:53-0500


import java.util.Scanner;


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		Scanner keyBoard = new Scanner(System.in);
		String names[] = new String[25];
		int marks[] = new int[25];
		for (int i = 0; i < 25; i++) {
			System.out.print("Enter the name " + (i + 1) + ": ");
			names[i] = keyBoard.nextLine();
			System.out.print("Enter the mark " + (i + 1) + ": ");
			marks[i] = keyBoard.nextInt();
			keyBoard.nextLine();
		}
		bubbleSort(names, marks);
		System.out.printf("%-15s%-15s\n", "Name", "Mark");
		for (int i = 0; i < 25; i++) {
			System.out.printf("%-15s%-15d\n", names[i], marks[i]);
		}
		keyBoard.close();
	}


	static void bubbleSort(String names[], int numbers[]) {
		int n = numbers.length;
		for (int i = 0; i < n - 1; i++)
			for (int j = 0; j < n - i - 1; j++)
				if (numbers[j] < numbers[j + 1]) {
					int temp = numbers[j];
					numbers[j] = numbers[j + 1];
					numbers[j + 1] = temp;


					String tempName = names[j];
					names[j] = names[j + 1];
					names[j + 1] = tempName;
				}
	}
}

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