public class CharSortTest { public static void main(String[] args) { char[] letters = {'j', 'a', 'z', 'y', 'x'}; char min = 0; char swap = 0; for (int x = 0; x <= letters.length - 1; x++) { min = letters[x]; for (int i = x + 1; i <= letters.length - 1; i++) { if (letters[i] < min) { min = letters[i]; } } if (letters[x] != min) { swap = letters[x]; letters[x] = min; min = swap; } } for (int p = 0; p <= letters.length - 1; p++) { System.out.println(letters[p]); } } }
output:
a a x x x
i followed the logic of selection sorting.. i even checked the integer values of each character in my array
but why is my program not sorting....