Question
IN SCALA Write a function named countVowels that inputs a String and outputs an Int which counts the number of occurrences of a vowel in
IN SCALA
Write a function named countVowels that inputs a String and outputs an Int which counts the number of occurrences of a vowel in a given string. Vowels are a, e, i, o, u. Capital letters of vowels should also count as a vowel.
Example:
Input: "aaatchoU"
Output: 5.
You may use for-loops/while loops and mutable vars for this particular problem. String or List API functions are also allowed.
Your program should pass the following tests:
testWithMessage( countVowels("atchou") , 3, "\"atchou\" must have three vowels in it" )
testWithMessage( countVowels(""), 0, "Empty string has no vowels")
testWithMessage( countVowels("AAEIOU"), 6, "Capitalized vowels handled")
testWithMessage( countVowels("Grzzly"), 0, "\"Grzzly\" has no vowels")
testWithMessage( countVowels("Meow, Meow, says the alley cat next door!!"), 12, "Handling commas and spaces?")
score=(score*1*10/5.0).round / 1.0
passed(score)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started