---
# System prepended metadata

title: Java_Cmoney_ft9105_找出孤獨的數字
tags: [Cmoney_Java題目]

---

---
tags: Cmoney_Java題目
---
Java_Cmoney_ft9105_找出孤獨的數字
===

![](https://i.imgur.com/fvB0kES.png)
![](https://i.imgur.com/NMsB6Fx.png)



1.主程式
---
1. 使用`Arrays.sort()`排序，如果隔壁的數字一樣，就變成 0 
2. 輸出不是 0 的數字
```java=
import java.util.Arrays;
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] numbers = new int[n];
        for (int i = 0; i < n; i++) {
            numbers[i] = sc.nextInt();
        }
        Arrays.sort(numbers);
        for (int i = 0; i < n - 1; i++) {
            if (numbers[i] == numbers[i + 1]) {
                numbers[i] = 0;
                numbers[i + 1] = 0;
            }
        }
        for (int i : numbers) {
            if (i != 0)
                System.out.println(i);
        }
    }
}
```

