Created
February 18, 2020 04:44
-
-
Save rahulkhatri19/8d1c01acd27f4ce95df50cef7b8d4cf4 to your computer and use it in GitHub Desktop.
For counting vowel in a string by Recursive method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var count = 0 | |
fun main(args: Array<String>) { | |
println("Enter string to Count Vowels: ") | |
val inputSt: String? = readLine()!! | |
// val inputSt: String? = "Hi this to check" | |
print(checkforVowel(inputSt, inputSt?.length)) | |
} | |
fun checkforVowel(inputSt: String?, length: Int?): Int { | |
if (length == 1){ | |
return isVowel(inputSt?.toCharArray()?.get(length.minus(1))) | |
} | |
else return checkforVowel(inputSt, length!!.minus(1)) + isVowel(inputSt?.toCharArray()?.get(length.minus(1))) | |
} | |
fun isVowel(ch:Char?): Int { | |
val checkVowel = ch?.toUpperCase() | |
if (checkVowel == 'A' || checkVowel == 'E' || checkVowel == 'I' || checkVowel == 'O' || checkVowel == 'U'){ | |
// count += 1 | |
return 1 | |
} else return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment