简体   繁体   中英

java String array in ascending order

I'd like to have the list be in ascending order via "sortAscending" and then send "showArray" and "sortAscending" to a textfile. "sortAscending(list);" isn't showing anything when running it, and there are no syntax errors.

sortAscending(list);
public static String[] sortAscending(String[] names)
{
    String temp;
    int passNum, i, result;
    for(passNum=1; passNum < 10; passNum++)
    {
        for(i = 0; i<(10-passNum); i++)
        {
            result=names[i].compareToIgnoreCase(names[i+1]);
            if(result>0)
            {
                temp=names[i];
                names[i]=names[i+1];
                names[i+1]=temp;
            }
        }
    }
    return names;
// Print sorted list 
sortAscending(list);

sortAscending is not printing anything. It just sorts the list. You probably want to

// Sort the list and print it
showArray(sortAscending(list));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM