读入10个整数,显示互不相同的数的数,并以输入顺序显示这些数字java
时间: 2024-06-03 11:06:55 浏览: 89
输入10个数,然后按顺序排列
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] arr = new int[10];
for (int i = 0; i < 10; i++) {
arr[i] = scanner.nextInt();
}
Set<Integer> set = new LinkedHashSet<>();
for (int i = 0; i < 10; i++) {
set.add(arr[i]);
}
Iterator<Integer> it = set.iterator();
while (it.hasNext()) {
System.out.print(it.next() + " ");
}
}
}
阅读全文