
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
// 使用HashSet来判断是否是不重复的
HashSet<Integer> hs = new HashSet<>();
// 获取代求解的值
int target = sc.nextInt();
// 求解每位上面的整数
while (target != 0) {
int temp = target % 10;
// 如果能加入,就是说明没有重复
if (hs.add(temp)) {
System.out.print(temp);
}
// 除10能去掉最右边的数字
target /= 10;
}
System.out.println();
}
}
}
去除重复数字的Java程序
本文介绍了一个简单的Java程序,该程序能够接收一个整数并输出该整数中不重复的数字组合。通过使用HashSet数据结构,程序可以有效判断并移除重复的数字。

被折叠的 条评论
为什么被折叠?



