就当做个笔记,主要用到了Hashset方法中add不能添加重复字段的属性,
再用.size得到长度
package com.test;
import java.util.HashSet;
import java.util.Scanner;
public class Test2 {
public void length(){
Scanner in=new Scanner(System.in);
String s=in.next();
char c[]=s.toCharArray();
int i;
int count;
int len=s.length();
HashSet<String> set = new HashSet<String>();
for(i=0;i<len;i++){
set.add(String.valueOf(c[i]));
}
count=set.size();
System.out.println(count);
}
public static void main(String args[]){
Test2 ts=new Test2();
ts.length();
}
}