I'm trying to alphabetize an array by comparing the characters at position 0 of two strings in an array, but I don't understand why when the if statement doesn't run my trail variable doesn't get incremented.
//alphabetize array
public class AlphaArray
{
public static void main(String[] args)
{
String[] yourChoiceItems =
{"Blueberry Muffins 0.85",
"Strawberry Bagels 0.80",
"Lite Yogurt 0.75",
"Vanilla Ice Cream 2.75",
"Hash Browns 2.50",
"Toast 2.00",
"French Fries 1.50",
"Onion Soup 3.00",
"Coffee 0.90",
"Iced Tea 1.00",
"Hot Chocolate 1.75"};
for(int i=0; i<yourChoiceItems.length-1; i++)
{
String trail = yourChoiceItems[i];//initially yourChoiceItems[0]
String current = yourChoiceItems[i+1];//initially yourChoiceItems[1]
String temp;//temporary string for if they need to be swapped
System.out.println("i is: "+i+"trail is: "+trail);
if(trail.charAt(0)>current.charAt(0))
{
temp = trail;
yourChoiceItems[i] = current;
yourChoiceItems[i+1] = temp;
}
}
}
}