输入一行没有空格的字符串。
输出范围在(0~127)字符的个数。
abc
1 import java.util.*; 2 import java.io.*; 3 4 // 可以看看ASCII对照表:https://baike.baidu.com/item/ASCII/309296?fromtitle=ascii%E7%A0%81&fromid=99077&fr=aladdin 5 public class Main{ 6 public static void main(String [] args) throws IOException { 7 //Scanner bufferReader = new Scanner(System.in); 8 //String line = bufferReader.nextLine(); 9 // 使用BufferedReader & InputStreamReader 会比直接使用Scanner运行速度快些 10 BufferedReader bufferReader = new BufferedReader(new InputStreamReader(System.in)); 11 String line = bufferReader.readLine(); 12 int [] lineArray = new int [127]; 13 int count = 0; // 统计重复的字符个数 14 // 遍历输入字符串的每一个字符,若首次出现将char对应的索引数组赋值,同时count + 1 15 for(int i = 0; i < line.length(); i++){ 16 char temp = line.charAt(i); 17 if(lineArray[temp] == 0){ // 数组未赋值默认值为 0 18 count++; 19 lineArray[temp] = 1; // 该cahr 数组索引赋值 20 } 21 // 假如输入tjt,第一次 lineArray[t] 赋值后,下次char为t的再过来就直接跳过 22 } 23 System.out.println(count); 24 } 25 }