Q:

Write a Ruby program to count the occurrences of a specified character in a given string

0

Write a Ruby program to count the occurrences of a specified character in a given string

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def check_string(my_string, chr)
   return my_string.count(chr) 
end
print check_string("JavaScript", "J")
print "\n",check_string("JavaScript", "a")
print "\n",check_string("JavaScript", "S")

Output:

1
2
1

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now