Status: Not Started
  • Scratchpad.java
  • Unit Test
Font Size
14
Parentheses autocomplete
Wrap lines
Editor
Theme
Code with blocks by default
Console Font Size
12
Console Theme
Display Server Graphics Screen
Show File Tab Bar
Debug Mode
Binary Search
Unit Test
public int search(int[] array, int value)
{
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Output
Grading
Docs
Exercise
More
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Pass Test Message

Errors:

This student is viewing this assignment in English. View this page in English?

7 points

Write a binary search method that takes a sorted int[] array and an int value to find, and returns the index where the value appears in the array.

For example:

binarySearch(new int[]{1, 2, 3, 4, 5, 6, 7, 8}, 3)

Should return

2

Because 3 appears at index 2 in the array.

If the value does not exist in the array, return -1.

binarySearch(new int[]{1, 2, 3, 4, 5, 6, 7, 8}, 10)

Should return

-1

Your job is to implement the binarySearch method. Your solution should be recursive, so your method should call itself.

Reset Code

Slides and Notes

No slides available for this video

About

Java Practice (main)
Java Version 1.8.0_222

Upload Media