Write a Ruby program to check a given string contains 'i' characters.
def test_str(str) count = 0 for i in 0..str.length do if(str.slice(i) == 'i') count = count + 1 end end return (count >= 1 && count <= 3); end print test_str('Python'),"\n" print test_str('Diligent1'),"\n" print test_str('Industrious'),"\n" print test_str('Impartiality')
Output:
false true true true
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer