Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
package binarysearch;
import java.util.Scanner;
public class Main {


    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
       int []a = new int [8];
       int low=0;
       int high=7;
       
       for(int i=0 ; i<a.length ; i++)
       {
     System.out.printf("\r\nPlease enter a number :",a[i]);
     a[i] = input.nextInt();
       }

     System.out.printf("\r\nPlease enter an integer :");
        int key = input.nextInt();

  //   System.out.printf("\r\nIt is in place "(binarysearch(numbers , low  ,high ,key)");

     public Static int binarysearch(int[]numbers,int key,int low , int high){

        if(low>high)
        {
            return -1;
        }
        int mid = (low + high)/2 ;
        if(numbers [mid] == key){
            return mid;

                if(key < numbers[mid])
                {
                    return binarysearch(numbers , low , mid-1 , key);
                }     else{
                        return binarysearch(numbers , mid+1,high , key);
   System.out.printf("\r\nIt is in place "(binarysearch(numbers , low  ,high ,key)");
                }
            
        }
        }
    }


I put this code between <pre></pre> tags in order to make it a) more readable and b) to show the basic mistakes; so why did you remove the tags and make it unreadable?
Posted
Updated 5-Feb-10 6:42am
v7

As an exercise I put your code between <pre></pre> tags (see the "code block" button atop the edit window), and corrected the alignment but not the code. As you can see there are a number of errors indicating (as javac would tell you) that this code does not even compile. Try correcting the syntax and see what happens.
 
Share this answer
 
That smiley you have in the code certainly won't compile...
 
Share this answer
 
If you ever watched Karate Kid, you shoudl remember 'wax on - wax off'. Everytime you apply the wax, you must remove the wax. Code is very similar, the great Code Ninjas of Syrias 4 always say 'Brace in, brace out'.

Finally as the great jedi would say 'This mantra apply yourself to you must.'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900