网站内容编辑怎么做,外贸流程及详细介绍,培训做网站,外贸行业建站kotlin中判断字符串Given a string and a character, we have to find the frequency of the character in the string. 给定一个字符串和一个字符#xff0c;我们必须找到字符串中字符的频率。 Example: 例#xff1a; Input:string IncludeHelpcharacter to…kotlin中判断字符串Given a string and a character, we have to find the frequency of the character in the string. 给定一个字符串和一个字符我们必须找到字符串中字符的频率。 Example: 例 Input:
string IncludeHelp
character to find e
Output:
2
在Kotlin中查找字符串中字符频率的程序 (Program to find the frequency of character in a string in Kotlin) package com.includehelp.basic
import java.util.*
//Main Function, entry Point of Program
fun main(args: ArrayString) {
// InputStream to get Input
val scanner Scanner(System.in)
//Input String
print(Enter String : )
val str scanner.nextLine()
//Input Character to check Frequency in Above input String
print(Enter Character : )
val c scanner.next()[0]
var frequency0
//Count Frequency
for (i in str.indices){
if(c str[i]){
frequency
}
}
//Print Frequency of Character
println(Frequency of $c is : $frequency)
}
Output 输出量 RUN 1:
Enter String : include help team
Enter Character : e
Frequency of e is : 3
---
Run 2:
Enter String : Kotlin is the Modern Programming Languagae
Enter Character : n
Frequency of n is : 4
翻译自: https://www.includehelp.com/kotlin/find-the-frequency-of-character-in-a-string.aspxkotlin中判断字符串