I'm trying to find the minimum value of numbers in an array but it doesn't always work out properly. This is the code I wrote:
for (int i=0; i < arr.length; i++) {
min = arr[i];
for (int j=0; j < arr.length; j++) {
if (arr[j] < arr[0]) {
min = arr[j];
}
}
}
Can someone explain to me what I did wrong and how I can improve the code?
arr[j] < arr[0]should bearr[j] < min.