package com.heima.test;
import java.util.HashSet;
import java.util.Scanner;
//使用Scanner从键盘读取一行输入,去掉其中重复字符, 打印出不同的那些字符
public class Test8 {
public static void main(String[] args) {
HashSet<Character> hs = new HashSet<Character>();
Scanner sc = new Scanner(System.in);
System.out.println("请输入字符串:");
String str = sc.nextLine();
char[] chars = str.toCharArray();
for(char ch:chars) {
hs.add(ch);
}
System.out.println(hs);
}
}
|
|