键盘录入任意字符 在控制台上不重复输出!!
package com.heima;
import java.util.HashSet;
import java.util.Scanner;
public class test4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入任意字符");
HashSet<Character> hs = new HashSet<>();
String line = sc.nextLine();
char[] arr = line.toCharArray();
for (char c : arr) {
hs.add(c);
}
for (Character cs : hs) {
System.out.println(cs);
}
}
} |
|