题解 | #合唱队#
package 华为.字符串;
//用HashMap的去重就能实现
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class 字符个数统计 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//输入字符串
String s = sc.nextLine();
//统计不同的字符个数
System.out.println(calue(s));
}
private static int calue(String s) {
char[] chs = s.toCharArray();
int len = s.length();
Map<Character, Integer> map = new HashMap<>();
for (int i = 0; i < len; i++) {
char ch = chs[i];
if (!map.containsKey(ch)) {
map.put(ch, 1);
}
}
return map.size();
}
}
//用HashMap的去重就能实现
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class 字符个数统计 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//输入字符串
String s = sc.nextLine();
//统计不同的字符个数
System.out.println(calue(s));
}
private static int calue(String s) {
char[] chs = s.toCharArray();
int len = s.length();
Map<Character, Integer> map = new HashMap<>();
for (int i = 0; i < len; i++) {
char ch = chs[i];
if (!map.containsKey(ch)) {
map.put(ch, 1);
}
}
return map.size();
}
}