Computer Science, asked by playstore3571, 7 months ago

1. Write a program to input percentage of 35 students of class X in one dimensional array. Arrange

students details according to their percentage in the descending order using selection sort method. Display

percentage of first ten toppers of the class.​

Answers

Answered by Oreki
0

import java.util.Scanner;

public class StudentMarks {

// Selection sorting the array.

static void selectionSort(float[ ] array) {

for (int i = 0; i < array.length; i++) {

float largest = array[i];

int position = i;

for (int j = i + 1; j < array.length; j++)

if (array[j] > largest) {

largest = array[j];

position = j;

}

array[position] = array[i];

array[i] = largest;

}

}

public static void main(String[ ] args) {

float[ ] marks = new float[10];

// Accepting marks.

System.out.println("Enter marks - ");

for (int i = 0; i < marks.length; i++)

marks[i] = new Scanner(System.in).nextFloat( );

// Sorting

selectionSort(marks);

// Printing first 10 toppers percentages.

System.out.println("\nFirst 10 toppers - ");

for (int i = 0; i < 10; i++)

System.out.print(marks[i] + "% ");

}

}

Similar questions