Page 467 - CA_Blue( J )_Class10
P. 467

Variable Description
                   NAME       DATATYPE                                     DESCRIPTION
                  i          int          Loop Variable
                  ar[]       int[]        Array

                  sum        int          Sum of the numbers
                  n          int          Size of Array

                 (b)  Programs based on sort techniques mentioned in the scope of the syllabus.


                               Write a program to accept the name and marks in computer science of "n" students in an array and
                  Program 10
                               print the name and marks of students merit wise.


                   1      import java.util.*;           //importing package "util"
                   2      class bubblesort           //Declaration of variables

                   3      {
                   4          public static void main()

                   5          {
                   6              Scanner sc= new Scanner(System.in);

                   7              int n;             // Declaration of variable
                   8              int i,j,tempmarks;

                   9              String tempname;
                  10              System.out.print("Enter number of students in the class : ");

                  11              n=sc.nextInt();
                  12              String name[] = new String[n];       //Creation of name array

                  13              int marks[] = new int[n];         //Creation of marks array
                  14              for(i = 0;i<n;i++)           // Taking elements in Array
                  15              {

                  16                  System.out.print ("Enter Name of student " + (i+1) +" : ");

                  17                  name[i] = sc.next() ;
                  18                  System.out.print ("Enter Comp. Sc. Marks : ");
                  19                  marks[i] = sc.nextInt();

                  20              }

                  21              for(i = 0;i<n-1;i++)     // Sort the array in Descending order in bubble
                              sort technique
                  22              {
                  23                  for(j = i+1;j<n;j++)

                  24                  {





                                                                                                                       465
                                                                                                   Internal Assessment  465
   462   463   464   465   466   467   468   469   470   471   472