-1

标签是将您的问题与其他类似问题分类的关键字或标签。标签是将您的问题与其他类似问题分类的关键字或标签。

4

2 回答 2

1

在以下三个代码块中,我将首先编写您的行,然后是它应该是什么:

String[] sort = new String[listNames];
String[] sort = new String[listNames.length];
                                    ^^^^^^^

for (int x = 0; x < sort; x++) {
for (int x = 0; x < sort.length; x++) {
                        ^^^^^^^

sort[x] = JOptionPane.showMessageDialog(" Tutor LAST NAME and FIRST NAME Listed in Alphabetically Order"+(x+1)+ " " + "For example: 'Smith, John'");
sort[x] = JOptionPane.showMessageDialog(null, " Tutor LAST NAME and FIRST NAME Listed in Alphabetically Order"+(x+1)+ " " + "For example: 'Smith, John'");
                                        ^^^^^

假设你真的想在排序之前创建一个新数组,你的方法应该是:

public static String[] sortNames(String[] listNames) {
    String[] copy = Arrays.copyOf(listNames, listNames.length);
    Arrays.sort(copy);
    return copy;
}

如果它必须是一个方法,但您不必创建第二个数组,您可以这样做:

public static void sortNames(String[] listNames) {
    Arrays.sort(listNames);
}
于 2013-04-05T22:38:53.557 回答
0

你应该改变

for (int x = 0; x < sort; x++) 

for (int x = 0; x < sort.length; x++)

反而。和

String[] sort = new String[listNames];

String[] sort = new String[listNames.length];

此外,JOptionPane.showMessageDialog()应该以这种方式使用:

JOptionPane.showMessageDialog(null," Tutor LAST NAME and FIRST NAME Listed in Alphabetically Order"+(x+1)+ " " + "For example: 'Smith, John'");
于 2013-04-05T22:35:38.437 回答