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

Abhisara - the Tryst Notes

Summers are becoming hotter with each passing year. Write a description of one such very hot day. What did you see and hear as you walked outside? How were birds and animals affected?

Java String Manipulation 28th Jan Practice 1 - to accept a character and check whether it is a letter or not. If letter, then convert it to uppercase or lowercase. Also check whether it is letter or a special character

Java String Manipulation 28th Jan Practice 2 - input a string and check whether it is a palindrome or not

Java Recursion Program Practise 5 - to input a number and print the sum of digits of the number

Java Recursion Program Practise 1 - Factorial

Java Recursion Program Practise 3 - Raising base to power of index

Java Recursion Program Practise 2 - Fibonacci Series

Write a short story entitled "Advice not taken"