题目描述
编写一个函数,计算字符串中含有的不同字符的个数。字符在ACSII码范围内(0~127)。不在范围内的不作统计。
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String inputStr = sc.next();
char[] charArray = inputStr.toCharArray();
int length = charArray.length;
int count = 0;
LinkedHashSet<Character> set = new LinkedHashSet<Character>();
for(int i=0;i<length;i++){
set.add(charArray[i]);
}
for(Character ch : set){
count++;
}
System.out.println(count);
}
}
}