我写的Java源代码是这样的:
import java.util.*;
public class SortTest
{
static int []y ;
public static void main(String[] args)
{
int []x= new int[]{7,65,83,1092,0,-2,877,63,838838,-3765};
java.util.Arrays.sort(x); //对数组进行排序,其实在此处也可写成 Arrays.sort(x)
System.out.println(Arrays.asList(x)); // 打印输出数组
System.out.println("该数组从大到小的排列顺序是:");
for(int counter = x.length-1;counter>=0;counter --)
{
int i = 0; if(i <=x.length-1)
{
i++;
} y[i] = x[counter];
System.out.println("/ny[" + counter + "]=" + y[i]);
}
}
}在Eclipse3.2里面运行的结果是:java.lang.NoClassDefFoundError: 17
Caused by: java.lang.ClassNotFoundException: 17
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main" 求高手指点啊,小弟分少,就悬10分,希望不吝赐教啊!!!
import java.util.*;
public class SortTest
{
static int []y ;
public static void main(String[] args)
{
int []x= new int[]{7,65,83,1092,0,-2,877,63,838838,-3765};
java.util.Arrays.sort(x); //对数组进行排序,其实在此处也可写成 Arrays.sort(x)
System.out.println(Arrays.asList(x)); // 打印输出数组
System.out.println("该数组从大到小的排列顺序是:");
for(int counter = x.length-1;counter>=0;counter --)
{
int i = 0; if(i <=x.length-1)
{
i++;
} y[i] = x[counter];
System.out.println("/ny[" + counter + "]=" + y[i]);
}
}
}在Eclipse3.2里面运行的结果是:java.lang.NoClassDefFoundError: 17
Caused by: java.lang.ClassNotFoundException: 17
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main" 求高手指点啊,小弟分少,就悬10分,希望不吝赐教啊!!!
public static void main(String[] args)
{
int[] x = new int[] { 7, 65, 83, 1092, 0, -2, 877, 63, 838838, -3765 }; java.util.Arrays.sort(x); //对数组进行排序,其实在此处也可写成 Arrays.sort(x)
for(int i = 0; i < x.length; i++)
{
System.out.println(x[i]);
}
}
* @param int型数组
* 将int类型的数组元素按从大到小顺序排列
*/
public void reSort(int[] a) {
int temp;
Arrays.sort(a);
for (int i = 0; i < a.length / 2; i++) {
temp = a[i];
a[i] = a[a.length - 1 - i];
a[a.length - 1 - i] = temp;
}
}
y = new int[x.length - 1];
其实我写这个程序的作用是将数组从大到小(sort方法是将数组从小到大排列的)输出,然后测试一下 asList 方法
//这样写比较好
static int[] y=new int[10];
用一个for 循环 ,假设 有一数组 a[n] (已经 从小到大 排好序):
int t=0;
for(int i=0;i<a.length/2;i++){
t=a[i];
a[i]=a[n-i-1]; a[n-i-1]=t;
}
你试一下 ,我没调试,但算法是对的 。