Write a program to input name and percentage of 35 students of class X in two separate
one dimensional arrays. Arrange students details according to their percentage in the
descending order using selection sort method. Display name and percentage of first
ten toppers of the class.
Answers
Answer:
50046810057✨✨
The program of the given question is as follows:
import java.util.Scanner ; // created scanner object
class School_Students // created class
{
public static void main(String[] args)
{
String a[ ] = new String[35]; // variable string is created
int b[ ] = new int[35]; // variable integer is creater
Scanner pin = new Scanner(System.in);
for (int i = 0; i < 35; i++) // loop
{
System.out.print("Enter the name of the student " + (i + 1) + " : "); //user gives input
a[i] = pin.nextLine();
System.out.print("Enter the percentage of the students : "); //user gives input
b[i] = pin.nextInt();
pin.nextLine();
}
int X=b.length;
for (int i=0; i<l-1; i++) // selection sort
{
int pop = i;
for (int j=i+1; j<l; j++)
{
if (b[j] > p[pop])
{
pop = j;
}
}
int X1 = b[pop];
b[pop] = b[i];
b[i] = X1; // percentage is swaped
String X2 = a[pop];
a[pop] = a[i];
a[i] = X2; // name is swaped
}
System.out.println("RANK \t NAME \t PERCENTAGE");
for (int i = 0; i < 10; i++)
{
System.out.println((i+1) + " \t " + a[i] + " \t " + b[i]); // top 10 students are printed
}
}
}