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

Translate

Popular posts from this blog

Letter to SBI Bank Manager of Local Branch to reduce the interest rate on home loan

Narrate an experience that shows appearances can be deceiving

Abhisara - the Tryst Notes

Macbeth Personal Notes: Act 1 Scene 3 (Part 1)

A village fair is very different from a city one. It is usually held annually and is connected with a religious festival or harvest. The purpose of such fair is usually trade and to exhibit and sell village handicrafts. Describe one such fair.

Describe a moment of pure joy or awe you experienced, using your words to paint a picture of the scene and evoke the emotions you felt

Imagine a situation where you get an opportunity to change one thing in your school. What would it be? Why do you want to change it? How would you bring about the change?

Macbeth Personal Notes: Act 1 Scene 3 (Part 2/2)

Completed the biography of 1st writer for Hindi project, now writing the secomd one