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

 

firstXY


Return the index of the first occurrence of x or y in a string, or return -1 if the string does not contain an x or y. Hint: String objects have an indexOf() method that returns the first occurrence of one string within another, or -1 if the string can't be found. For example, if str is "mississippi", then str.indexOf("m") returns 0, str.indexOf("s") returns 2, and str.indexOf("q") returns -1.


firstXY("box") → 2
firstXY("boxy") → 2
firstXY("yx") → 0

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

int firstXY(String str) { }

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

Difficulty: 100

Copyright Nick Parlante 2017 - privacy