+ 1

Java code (Find same int from arrays)

There got one more same int from both array which is 2 , why 2 didn't print out? https://code.sololearn.com/c6P5wOuS39kR

7th Jun 2019, 3:50 PM
Tzion
Tzion - avatar
3 Réponses
+ 2
It's because you start at the i index of the array, so when it gets to the number 2 in the array (which has the index 2), x starts from 2, but in the second array, it's index is 0, so it can't be found. In the second loop you have to start x from 0
7th Jun 2019, 3:57 PM
Airree
Airree - avatar
+ 1
// for(int x = i;x < arr2.length;x++){ for(int x = 0;x < arr2.length;x++){ // x=0
7th Jun 2019, 7:10 PM
zemiak
0
Airree Thank you so much zemiak Thank you too! i've add comments to my code
8th Jun 2019, 1:37 AM
Tzion
Tzion - avatar