Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Shavit Borisov
- // CW
- public class Find25 {
- public static void main(String[] args)
- {
- final int SIZE = 20;
- final int KEY = 25;
- int[] A = new int[SIZE]; // Needs to be initialized with sorted values
- System.out.printf("%d was found %d times in array A[%d]", KEY, findKey(A, KEY), SIZE);
- }
- private static int findKey(int[] array, int key)
- {
- int result = 0;
- for(int i = 0; i < array.length; i++)
- {
- if(array[i] > key)
- break;
- else if(array[i] == key)
- result++;
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement