题解 | #字符个数统计#

字符个数统计

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

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

/**
 * 【字符个数统计】
 *
 *  描述:编写一个函数,计算字符串中含有的不同字符的个数。
 *
 *  【不采用集合去重】
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      	// 输入 
        String nextLine = sc.nextLine();
      
        char[] chars = nextLine.toCharArray();
        char[] newChars = new char[chars.length];

        int count = 0;
        for (int i = 0; i < chars.length; i++) {
            boolean flag = false;
            for (int j = 0; j < newChars.length; j++) {
                if (chars[i] == newChars[j]) {
                    flag = true;
                }
            }

            if (!flag) {
                newChars[i] = chars[i];
                count++;
            }
        }
        System.out.println(count);
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
04-27 15:01
早稲田大学 Java
牛客72191338...:可能是时间点的问题,四月底机会确实会相对少点,但佬这个学历摆在这,会有机会的
简历中的项目经历要怎么写
点赞 评论 收藏
分享
评论
5
2
分享

创作者周榜

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