帮看看哈哈
//导入Arrays类
import java.util.Arrays;
public class HelloWorld {
public static void main(String[] args) {
// 定义一个字符串数组
String[] hobbies = { "sports", "game", "movie" };
// 使用Arrays类的sort()方法对数组进行排序
Arrays.sort(hobbies);
System.out.println("运行结果为:");
// 使用Arrays类的toString()方法将数组转换为字符串并输出
for(int i=0;i<hobbies.length;i--)
{
hobbies[i]=Arrays.toString(hobbies);
System.out.print(hobbies[i]);
//System.out.print(hobbies[i]);
}
//System.out.println(Arrays.toString(hobbies));
}
}
/*运行失败
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at HelloWorld.main(HelloWorld.java:18)
运行结果为:
[game, movie, sports]*/