[英]traversing arrays using for loops in java
我想比較兩個數組中的數字,其中 array1[start] 與 array2 進行比較並與每個 array2 元素進行比較,然后在完成后增加 array1 索引。 這是我到目前為止所得到的
for(int i=0; i<array1.length; i++){ // move along array 1
if(array1[i]>array2[j]){
//do something
}
for(int j =0; j<array2.length; j++){ // moves along array 2
}
}
這可能就是你想要的。
for(int i=0; i<array1.length; i++){ // move along array 1
for(int j=0; j<array2.length; j++){ // moves along array 2
if(array1[i]>array2[j]){
//do something
}
}
}
您放置的核心邏輯塊位於錯誤的范圍內。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.