I am studying Java and trying to find the bug in my code.
It is suppose to return the smallest element of the given non-empty array.
It works with B = [-3, 4, -2, -2]
Can you tell me what I am doing wrong here?
class Test {
int test(int[] B, int[] C) {
int ans = 0;
for (int i = 1; i < B.length; i++) {
if (ans > B[I]) {
ans = B[i];
}
}
return ans;
}
}