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: Array<String>) {
// 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 frequency=0
//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.aspx

kotlin中判断字符串

kotlin中判断字符串_Kotlin程序查找字符串中字符的频率相关推荐

  1. kotlin中判断字符串_Kotlin程序删除字符串中所有出现的字符

    kotlin中判断字符串 Given a string and a character, we have to remove all occurrences of the character in g ...

  2. kotlin 字符串_Kotlin程序确定字符串是否具有所有唯一字符

    kotlin 字符串 Given a string, we have to check whether it has all unique characters or not. 给定一个字符串,我们必 ...

  3. kotlin 字符串去空格_Kotlin程序从字符串中删除所有空格

    kotlin 字符串去空格 Given a string, we have to remove all whitespaces from it. 给定一个字符串,我们必须从中删除所有空格. Examp ...

  4. python字符串查找重复项,Python程序查找字符串中所有重复的字符

    在本教程中,我们将学习如何在字符串中查找所有重复值.我们可以在Python中以不同的方式进行操作.让我们一一探讨. 我们要编写的程序的目的是查找字符串中存在的重复字符.例如,我们有一个字符串tutor ...

  5. [转载] kotlin 字符串_Kotlin基本类型字符串

    参考链接: Python字符串串联Concatenation kotlin 字符串 Kotlin has five basic data types. In a previous post, we d ...

  6. C语言中删除字符串中一个字母,C程序删除字符串中除字母之外的所有字符

    C程序删除字符串中除字母之外的所有字符 在此示例中,您将学习从用户输入的字符串中删除除字母之外的所有字符. 要理解此示例,您应该了解以下C语言编程主题: 删除字符串中除字母之外的字符#include ...

  7. scala反转字符串_Scala程序反转字符串

    scala反转字符串 反转字符串 (Reversing a string) Logically, reversing is swapping the values from index 1 with ...

  8. PHP字符串函数stripos(查找字符串首次出现的位置,不区分大小写)

    在PHP中,字符串函数 stripos() 用来查找一个字符串在另一个字符串中首次出现的位置.     函数语法: stripos ( string $str , string $find [, in ...

  9. PHP字符串函数strrpos(查找字符串最后一次出现的位置,区分大小写)

    在PHP中,字符串函数 strrpos() 用来查找一个字符串在另一个字符串中最后一次出现的位置.     函数语法: strrpos( string $str , string $find [, i ...

最新文章

  1. 织梦html引入html代码,织梦标签引入共html.doc
  2. 图森未来完成2.15亿美元D轮融资,将拓展无人驾驶运输服务
  3. 一行命令堆出你的新垣结衣,不爆肝也能创作ASCII Art
  4. Statement接口实现查询数据、添加数据
  5. error: RPC failed; curl 18 transfer closed with outstanding read
  6. java集合框架介绍_Java集合框架介绍
  7. 推荐neter常用优秀开源项目系列之一
  8. 光端机的技术指标及构成有哪些?
  9. C#AE创建FeatureDataset/创建数据、集要素集
  10. php mysql 高效,php+mysql 大容量数据高效分页效果(弃用limit)
  11. Mysql Literal(文字,既常量)
  12. zmodem transfer cancled by remote side 解决办法
  13. idea卸载不干净怎么办_卸载删除面具(Magisk)后,手机不开机怎么办
  14. 服务器密码忘记处理之二:重置密码
  15. 去年车载终端营收下滑近7成,有方科技的车联网困局
  16. 研发团队建设的心得体会
  17. 浅谈umi router
  18. python的scipy层次聚类参数详解
  19. Android studio游戏开发就是这么简单:卡牌杀系列(核心UI篇:SufaceView的核心用法)
  20. android 通过电话号码来获取联系人姓名

热门文章

  1. 构建前端自动化工作流环境
  2. jQuery之合成事件
  3. 02-再探MySQL数据库
  4. 微信小程序开发——点击按钮退出小程序的实现
  5. KNNClassifier
  6. JavaScript DOM介绍
  7. NFS网络共享文件系统
  8. 138.括号序列(区间型DP)
  9. 关于easyui的一些小知识点(1)
  10. Resharper4.5:增强你的.net开发