Hello there, I'm doing an exercise we're you're supposed to sort strings in alphabetical order, without importing anything , aka, not using the Arrays.sort() method.
I think I got the method down partially right, or it is on the right track, but it is completely not being applied to my answer. All it prints out in the console is the actual String array twice, without sorting anything. Any ideas?
Thanks in advance.
public class arrayofstrings { public static void sort(String[] a) { String temp= ""; int min; int i= 0; for (int j=0; j<a.length-1; j++) { min = i; for (i=j+1; i<a.length; i++) if (a[i].compareTo(a[min]) <0) min = i; if(min!= j) temp = a[j]; a[j] = a[min]; a[min] = temp; } } public static void main(String[] args) { String[] a={"Rokas, Ausra, Tomas, Agne, Zenius"}; for (int i=0; i<a.length; i++) System.out.print(a[i]+" "); System.out.print("\n"); sort(a); for (int i=0; i<a.length; i++) System.out.print(a[i]+" "); System.out.print("\n"); } }