fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. int arr[]={1,2,3,4,5,6,7,8,9};
  14. int l=0;
  15. int r=arr.length-1;
  16. int target=9;
  17. int flag=0;
  18. while(l<=r){
  19. int mid=(l+r)/2;
  20. if(arr[mid]==target){
  21. flag=1;
  22. break;
  23.  
  24. }
  25. else if(arr[mid]>target){
  26. r=mid-1;
  27. }
  28. else{
  29. l=mid+1;
  30. }
  31. }
  32. if(flag==1)
  33. System.out.println("True");
  34.  
  35. else{
  36. System.out.println("False");
  37. }
  38. }
  39. }
Success #stdin #stdout 0.07s 16524KB
stdin
Standard input is empty
stdout
True