//这是一个选彩球的程序,但是结果输出不了,就是排序后的。import java.lang.reflect.Array;import javax.swing.JOptionPane;
public class ArraySort { private static final int index = 0; /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
String strIn = JOptionPane.showInputDialog("请输入一共多少个彩球:");
String strOut = JOptionPane.showInputDialog("请输入抽取过少个彩球:");
int in = Integer.parseInt(strIn);//强制转换成整型
int[] total = new int[in];//生成彩球总数数组
for(int i = 0;i < in; i++)
{
total[i] = i+1;
}

int [] out = new int[Integer.parseInt(strOut)];
for(int i = 0; i < out.length; i++)
{
int r = (int)Math.random() * in;//产生随即元素序列号
out[i] = total[r];
total[r] = total[in - 1];//将最后一个元素一道当前位置,把取出的删除
in--;
}
Array.getShort(out, index);
//Arrays.sort(out);
System.out.println("抽取的数字排序后是:");
for(int i = 0; i < out.length;i++)
{
System.out.print(" "+out[i]);
}
System.exit(0);

}}

解决方案 »

  1.   

    Array.getShort(out,index);的问题吧!Array是用来操作数组的,getShort用于取short[]数组的其中一个元素,你的out的类型是int[],肯定会IllegalArgument啦!而且这个也不是排序的吧
      

  2.   

    String strIn = JOptionPane.showInputDialog("请输入一共多少个彩球:"); 
    String strOut = JOptionPane.showInputDialog("请输入抽取过少个彩球:"); 
    你的这两句调用了JAVA图形控件,但又没把控件放到控件容器中,你可以看一下JAVA的GUI编程,把代码完善一下