在java集合 我應該得到用戶輸入爲整數並按升序排序。按用戶輸入的Java集合
import java.util.*;
import java.io.*;
class ArrayToCollection{
public static void main(String args[]) throws IOException{
BufferedReader in = new BufferedReader
(new InputStreamReader(System.in));
System.out.println("How many elements you want to add to the array: ");
int n = Integer.parseInt(in.readLine());
int[] num = new int[n];
for(int i = 0; i < n; i++){
num[i] = in.readLine();
}
TreeSet<String> setA =new TreeSet<String>();
setA.add(num);
System.out.println(setA.contains(num));
}
}
什麼是你的問題?預期的結果是什麼?什麼是實際結果? –
(請不要太過分了,OP是新的,並且顯示了他的嘗試。) –