InterviewSolution
| 1. |
Write a program to input name andpercentage of N student of class-10 in twoseparate one dimension arrays. Arrangestudent’s details according to theirpercentage in the descending order usingbubble sort method. Display name andpercentage of first ten topper of the class. |
|
Answer» Explanation:The program of the given QUESTION to display name and percentage of first ten toppers of the class is as follows: import java.util.Scanner ; // created object CALLED scanner class School_Students // created class named School_Students { public static void main(String[] args) { String a[ ] = new String[35]; // variable string int b[ ] = new int[35]; // variable integer 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) + " : "); // input from user is asked a[i] = pin.nextLine(); System.out.print("Enter the percentage of the students : "); //input from user is asked b[i] = pin.nextInt(); pin.nextLine(); } int X=b.length; for (int i=0; i { int POP = i; for (int j=i+1; 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 and their percentages are printed } } } |
|