题解 | #字符个数统计#
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s =br.readLine(); char[] array = s.toCharArray(); HashSet<Character> set = new HashSet(); for(int i=0;i<array.length;i++){ //判断字符是否在 ASCII 码范围内( 0~127 ,包括 0 和 127 ),直接用char和int值比较即可 if(array[i]>=0&&array[i]<=127){ set.add(array[i]); } } System.out.println(set.size()); } }