-1
我需要從控制檯獲取兩個1-D陣列進行比較練習。用戶輸入的第一個數字被指定爲數組的長度。用戶輸入長度和陣列成員,兩個陣列
當我嘗試提交第二個數組的數字時,我的代碼會報錯。 謝謝!
public static boolean Equals(int [] list1, int[] list2)
{
if(list1.length != list2.length) return false;
for (int i = 0; i < list1.length ; ++i)
if (list1[i] != list2[i]) return false;
return true;
}
public static void main (String[]args)
{
Scanner input = new Scanner(System.in);
//Prompt user for input
int[] list1 = null, list2 = null;
System.out.print("Enter list1: ");
int x = input.nextInt();
int []length = new int [x];
for (int i = 0; i < list1.length ; i++) {
x += list1[i];
System.out.print("Enter list2: ");
for (int j = 0; j < list2.length; j++) {
x += list2[j];
}
if (Equals (list1, list2))
System.out.print("Two lists are strictly identical");
else
System.out.print("Two lists are not strictly identical");
}
你錯過了一個'}' – 2014-10-28 11:17:27