Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
1.6
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { int[] a = {0, 1, 2, 3, 4}; //int x = 0; println("a[]: " + Arrays.toString(a)); for(int x : a){ println("___________________"); println(" x = " + x); A(a, x); B(a, x); C(a, x); } } public static void A(int[] ar, int x){ println(" --- A ---"); int i=0, j = ar.length-1, k, t = 0; do{ t++; k=(i+j)/2; println("k="+k+" i="+i+" j="+j); if(ar[k]<x){ i = k; }else{ j = k; } }while(((i<=j) && (ar[k]!=x) && t<10) ); println("---- end A --- k="+k+" ar[k]="+k+" t="+t); } public static void B(int[] ar, int x){ println(" --- B ---"); int i=0, j = ar.length-1, k, t = 0; do{ t++; k=(i+j)/2; if(x<ar[k]){ j = k-1; } if(ar[k]<x){ i = k+1; } }while((i<=j) && (t<10)); println("---- end B --- k="+k+" ar[k]="+k+" t="+t); } public static void C(int[] ar, int x){ println(" --- C ---"); int i=0, j = ar.length-1, k, t = 0; do{ t++; k=(i+j)/2; if(x<ar[k]){ j = k; }else{ i = k+1; } }while((i<=j) && (t<10)); println("---- end C --- k="+k+" ar[k]="+k+" t="+t); } public static void println(String s){ System.out.println(s); } }
run
|
edit
|
history
|
help
0
boolean1
HelloWorld2
Leetcode 202 Happy Number
test1
4pr
Fibonnaci + Prime number combined
191fa07050(1(D))
twelveDays
Rabbits in forest (leetod)
test1