Two versions of very similar code... one works, the other doesn't...
Array Used:
int[] input = new int[10];
//
for(int i = 0; i < input.length; i++) {
//int inputi = input[i];
for(int j = 0; j < input.length; j++) {
//int inputj = input[j];
if(input[i] < input[j]) {
input[j] = input[i];
min = input[j];
}
}
The code above works. The code below doesn't, what gives?
for(int i = 0; i < input.length; i++) {
int inputi = input[i];
for(int j = 0; j < input.length; j++) {
int inputj = input[j];
if(inputi < inputj) {
inputj = inputi;
min = inputj;
}
}
Shouldn't it do the exact same thing? The first code returns the minimum value, the second does not.
Sorry for the possibly confusing variable names, I only chose those so I could easily switch back and forth.