题解 | #计算某字符次数#

计算某字符出现次数

http://www.nowcoder.com/practice/a35ce98431874e3a820dbe4b2d0508b1

1.分别读取两行输入并初始化为str1,str2
2.将两个字符串均最小化处理
3.遍历str1查找str2的个数
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str1 = sc.nextLine().toLowerCase();
        int length = str1.length();
        String str2 = sc.nextLine().toLowerCase();
        int count = 0;
        for(int i = 0; i<length; i++){
            if(str1.substring(i,i+1).equals(str2)){
                count++;
            }
        }
        System.out.println(count);
    }
}
全部评论

相关推荐

2024-12-30 22:31
吉首大学 Web前端
工字钢写代码:改成吉林就OK了
点赞 评论 收藏
分享
01-26 22:20
已编辑
门头沟学院 Java
Java抽象带篮子:项目很nb了,现在好好准备八股和算法吧,早点找实习,可以看看我的置顶帖子。帖子里写了怎么改简历,怎么包装实习经历,还有2个高质量可速成的项目话术,和我的牛客八股笔记专栏
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务