Update index.md
1. while the array is larger than the target number of variable:"searchFor" , it is no need to search for the result that is larger than the "search target", therefore, we should break the loop to save more resources. 2. the variable j in the statement of "System.out.println("i = " + j); " is not declare and initialize at the beginning, also, var j in the while loop does not match with the variable i which is the result we want to display. Therefore, this statement should correct to "System.out.println("i = " + i); " so as to display the result of each loop correctly.
This commit is contained in:
committed by
Kristofer Koishigawa
parent
5da9e0bbca
commit
ae147f519a
@ -67,8 +67,8 @@ int i = 0;
|
|||||||
int searchFor = 5;
|
int searchFor = 5;
|
||||||
|
|
||||||
while(i < 10){
|
while(i < 10){
|
||||||
System.out.println("i = " + j);
|
System.out.println("i = " + i);
|
||||||
if(arrayOfInts[i] > 7){
|
if(arrayOfInts[i] > searchFor){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user