import java.util.HashSet;
import java.util.Scanner;
public class Demo4 {
/**
* Scanner接收一行输入 去除重复的字符,打印不同的字符
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个字符串:");
String line = sc.nextLine();
HashSet<Character> hs = new HashSet<>();
char[] c = line.toCharArray();
for (char d : c) {
hs.add(d);
}
for (Character d : hs) {
System.out.print(d+" ");
}
}
}
|
|