Category: searching java

Binary search in java

Binary Search program in Java

import java.io.DataInputStream; // to load DataInputStream class class BinarySearch { public static void main(String args[ ]) { int i,n = 0,KEY, flag=0; String ans="y"; int x[] = new int[25]; DataInputStream in = new DataInputStream(System.in);...

Linear search in java

Linear Search program in Java

class operation { static int Linear_Search(int K[], int n, int KEY) { int i; for(i=1;i<=n;i++) if(KEY == K[i]) return(i); return(-1); } } class searching { public static void main(String args[ ])throws IOException { int...