I'm trying to implement a very simple sorting method that takes int array and sorts elements in ascending order, but I'm stuck with errors about variables
public int[] sort1(int[] a){
for (int i=0; i<a.length;i++)
for(int j=i+1; j<a.length; j++)
int min = a[i];
if (a[j] < min) {
a[i] = a[j];
a[j] = min;
min = a[i];
}
return a;
}
i cannot be resolved to a variable j cannot be resolved to a variable min cannot be resolved to a variable
I don't know why these errors come up and how to fix them.
{afterfor(int j=i+1; j<a.length; j++)(and}later)fororifstatements contain a single statement. It'll save you from errors exactly like this.