字母 非重复字符串个数(Java)

题目来源

https://www.nowcoder.com/exam/test/83198992/detail?pid=54768478

其中的第291题

题目内容如下图

我的代码如下

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();

        int cnt=0;
        for(char ch='a';ch<='z';ch++){
            if(str.indexOf(ch)!=-1 && str.indexOf(ch) == str.lastIndexOf(ch)){
                cnt++;
            }
        }
        for(char ch='A';ch<='Z';ch++){
            if(str.indexOf(ch)!=-1 && str.indexOf(ch) == str.lastIndexOf(ch)){
                cnt++;
            }
        }

        System.out.println(cnt);
    }
}

运行结果

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 11:31
点赞 评论 收藏
分享
06-04 09:27
门头沟学院 Java
点赞 评论 收藏
分享
07-07 12:25
门头沟学院 Java
程序员牛肉:你这个智邮公司做的就是那个乐山市税务系统的服务吗?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务