Eclipse編譯成功,丟上來編譯失敗,求Java高手相助,
以下是錯誤訊息以及我的Code:
第 1 測資點(0%): CE ()
編譯錯誤
/code_2098277.java:18: error: cannot find symbol list.sort(null); ^ symbol: method sort() location: variable list of type ArrayList 1 error
import java.util.ArrayList; import java.util.Scanner; public class a010 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); ArrayList<Integer> list = new ArrayList<Integer>(); for (int i = 2; i <= n; i++) { if (n % i == 0) { list.add(i); n /= i; } } if (n != 1) list.add(n); list.sort(null); if (list.size() == 1) System.out.print(list.get(0)); else { System.out.print(list.get(0)); for (int i = 1; i < list.size(); i++) { if (list.get(i) == list.get(i -1)) { System.out.print("^"+list.get(i)); } else System.out.print("*"+list.get(i)); } } System.out.println(); } sc.close(); } }
Eclipse編譯成功,丟上來編譯失敗,求Java高手相助,
以下是錯誤訊息以及我的Code:
第 1 測資點(0%): CE ()
編譯錯誤/code_2098277.java:18: error: cannot find symbol list.sort(null); ^ symbol: method sort() location: variable list of type ArrayList 1 error
import java.util.ArrayList; import java.util.Scanner; public class a010 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); ArrayList<Integer> list = new ArrayList<Integer>(); for (int i = 2; i <= n; i++) { if (n % i == 0) { list.add(i); n /= i; } } if (n != 1) list.add(n); list.sort(null); if (list.size() == 1) System.out.print(list.get(0)); else { System.out.print(list.get(0)); for (int i = 1; i < list.size(); i++) { if (list.get(i) == list.get(i -1)) { System.out.print("^"+list.get(i)); } else System.out.print("*"+list.get(i)); } } System.out.println(); } sc.close(); } }