简体   繁体   English

java String数组升序

[英]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”将列表按升序排列,然后将“ showArray”和“ sortAscending”发送到文本文件。 "sortAscending(list);" “sortAscending(列表);” 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. sortAscending不打印任何内容。 It just sorts the list. 它只是对列表进行排序。 You probably want to 你可能想

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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