夥計們我在使用java時有點新,而且我正在嘗試編寫一個程序,它將檢查2d數組是否包含1d數組的值。第二個數組類似於數字列表,它將檢查第一個數組是否匹配。在Java中將2d數組與1d進行比較
array1[6]= {"a","b","c","d","e","f"}
array2[1][4]={{"a","b","c","d"}{"d","e","f","g"}}
array2[0]= rowcomplete ; // because it contain all the value a,b,c,d
array2[1]= incomplete; // because it only match d,e,f but not g
這是我的代碼:
String array1[] = {"a","b","c","d","e","f"};
String array2[][] = {{"a","b","c","d"}, {"d","e","f","g"}};
for (int 2row = 0; 2row < array2.length; 2row++) {
for (int 2column = 0;2column< array2[2row].length;2column++) {
for(int 1row=0; 1row < array1[1row].length();1row++) {
if (array2[2row][2column].equals(array1[1row])) {
System.out.println("complete");
}
else{
}
}
}
}
爲什麼所有的變量都以數字開始?它不會編譯。 –
哦!對不起我的錯誤,也是array1 [] = {「a」,「b」,「c」,「d」,「e」,「f」}和array2 [] [] = {{「a」 ,「c」,「d」} {「d」,「e」,「f」,「g」}} – user1030431