Page 394 - CA_Blue( J )_Class10
P. 394

12                    if(es == a[mid])
                13            {     pos = mid;

                14                                    break;
                15            }

                16                    else if(es < a[mid])
                17                              max = mid - 1;

                18                    else
                19                              min = mid + 1;

                20                }
                21                if(pos!=-1)

                22                    System.out.println(es + " found at index " + mid);
                23                else
                24                    System.out.println("Search element not found");

                25           }

                26  }
              You will get the following output:
              Element to search: 9
              9 found at index 2

                              To input 10 numbers in an array and sort the numbers in ascending order. (Use Bubble sorting
                Program 13
                              technique)

                 1  import java.util.*;

                 2  class Bubble_sort
                 3  {

                 4      public static void main()
                 5      {

                 6          Scanner sc= new Scanner(System.in);
                 7          int ar[]=new int[10];

                 8          int i,j,temp;
                 9          for (i=0; i<10; i++)

                10          {   System.out.print("Enter a number : ");
                11              ar[i] =sc.nextInt();

                12          }
                13          for(i=0;i<9;i++)

                14      {    for(j=0;j<9-i;j++)




                392392  Touchpad Computer Applications-X
   389   390   391   392   393   394   395   396   397   398   399