题解 | #字符个数统计#
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
import java.io.*; import java.util.*; import java.util.Set; public class Main { public static void main(String[] args) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String str=null; while((str=br.readLine())!=null){ int n=str.length(); Set set=new HashSet(n);//创建哈希集合 char ps[]=str.toCharArray();//字符串转换成字符数组 for (int i : ps) { set.add(i); } //遍历集合添加元素 System.out.println(set.size());//输出集合的大小 } } }