The way I'd do it (well, if I had to write a basic sort algorithm) would be to do a bubble sort: Bubble sort - Wikipedia[^]

Yours doesn't do that - it kinda stops too early, so the output order is a little odd.

But it's easy to solve! Just change this:

for (int k = j + 1; k < arrayLength - 1; k++)To this:

for (int k = j + 1; k < arrayLength; k++)