program 1

import java.util.*;

public class MyClass {

    public static void main(String args[]) {

        Scanner in = new Scanner (System.in);

      

      int n, ns, lb =0, ub =9, p=0,k=0;

      int m[] = new int [10];

      

      System.out.println("Enter the array");

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

          m[i] = in.nextInt();

      }

      System.out.println("enter number to be searched");

      ns = in.nextInt();

      

      while (lb<ub){

      p = (lb+ub)/2;

      if (m[p]<ns)

      lb = p+1;

      if (m[p]>ns)

      ub = p-1;

      if (m[p] == ns){

      k =1;

      break;

    }

      }

      if (k==1)

      System.out.println("Search successful");

      else

      System.out.println("Not");

      

    }

}

Comments

Popular posts from this blog

You are taking a leisurely stroll in a beautiful garden. Describe what you see around you, adding details about the sounds and the scents

Write an original short story entitled: ‘A Narrow Escape’.

'Tradition is an obstacle to progress.' Express your views either for or against this statement.