题解 | #字符个数统计#

字符个数统计

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

思路

1、Set集合具有去重功能

2、字符串可以截取每一个

3、该题中字符的大小写不区分


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Set<String> resultSet = new HashSet<String>();
		try (Scanner scanner = new Scanner(System.in)) {
			String line = scanner.nextLine().toLowerCase();
			for(int i=0;i<line.length();i++) {
				resultSet.add(line.substring(i,i+1));
			}
		}
		System.out.println(resultSet.size());
	}
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 11:29
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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