题解 | #提取不重复的整数#
提取不重复的整数
http://www.nowcoder.com/practice/253986e66d114d378ae8de2e6c4577c1
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int target = sc.nextInt();// 获取屏幕输入的值
// 使用HashSet来判断是否是不重复的
LinkedHashSet<Integer> hs = new LinkedHashSet<>();
while(target != 0){ // 求解每位上面的整数
int temp = target % 10;
hs.add(temp); // 如果能加入,就是说明没有重复
target /= 10;// 除10能去掉最右边的数字
}
for(Integer next : hs){
System.out.print(next);}//遍历打印出数值
}
}
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int target = sc.nextInt();// 获取屏幕输入的值
// 使用HashSet来判断是否是不重复的
LinkedHashSet<Integer> hs = new LinkedHashSet<>();
while(target != 0){ // 求解每位上面的整数
int temp = target % 10;
hs.add(temp); // 如果能加入,就是说明没有重复
target /= 10;// 除10能去掉最右边的数字
}
for(Integer next : hs){
System.out.print(next);}//遍历打印出数值
}
}
查看9道真题和解析