id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

tmhscs@gmail.com search > binarySearch_string
prev  |  next  |  chance

Given a String and a target letter, use the binary search algorithm to return the index where that letter appears in the String. Return -1 if the letter does not exist. Note: The String's letters are already sorted alphabetically and you must use binary search to receive credit for this problem. (Hint: Use the compareTo method for this problem!)


binarySearch_string("first", "f") → 0
binarySearch_string("effort", "f") → 2
binarySearch_string("glory", "r") → 3

...Save, Compile, Run (ctrl-enter)

public int binarySearch_string(String str, String letter) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Post-solution available

Copyright Nick Parlante 2017 - privacy