手头上有一代码,不知道怎么加进main中。就是加进public static void main中,或者补充为一个可以单独运行的程序,可以编译运行,立即给分。
能给其编写到一个图形界面的话,用AWT,不是用swing。立即追加到100分。在线等~~~~
public static int[] randoms()
{
Random r = new Random();int temp1,temp2;
int send[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21};
int len = send.length;
int returnValue[] = new int[22];
for(int i=0;i<22;i++)
{
temp1 = Math.abs(r.nextInt())% len;
returnValue[i] = send[temp1];
temp2 = send[temp1];
send[temp1] = send[len-1];
send[len-1] = temp2;
len--;
}
return returnValue;
}

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【noaighost】截止到2008-07-29 15:03:47的历史汇总数据(不包括此帖):
    发帖的总数量:5                        发帖的总分数:120                      每贴平均分数:24                       
    回帖的总数量:2                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:4                        结贴的总分数:100                      
    无满意结贴数:2                        无满意结贴分:20                       
    未结的帖子数:1                        未结的总分数:20                       
    结贴的百分比:80.00 %               结分的百分比:83.33 %                  
    无满意结贴率:50.00 %               无满意结分率:20.00 %                  
    楼主加油
      

  2.   

    难道CSDN的人全是来混分的?没有人吗?
      

  3.   

    直接在main 里面调用啊. 
    public static ,静态直接调用
      

  4.   


    import java.util.Random;public class Test {    public static void main(String[] args) {
            int []result=randoms();
            for (int i = 0; i < result.length; i++) {
                System.out.print(result[i]+" ");
            }
        }    public static int[] randoms() {
            Random r = new Random();        int temp1, temp2;
            int send[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
            int len = send.length;
            int returnValue[] = new int[22];
            for (int i = 0; i < 22; i++) {
                temp1 = Math.abs(r.nextInt()) % len;
                returnValue[i] = send[temp1];
                temp2 = send[temp1];
                send[temp1] = send[len - 1];
                send[len - 1] = temp2;
                len--;
            }
            return returnValue;
        }
    }       
      

  5.   

    lz得回家好好补下基础,两年内不上CSDN.
      

  6.   

    import java.util.Random;
    import java.awt.*;
    import java.awt.event.*;public class Text extends Frame implements ActionListener
    {
    TextField text;
        public Text()
        {
             super("Text");
             this.setSize(400,100);
             this.setLocation(200,200);
             this.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT));
            
             
             Button button = new Button("Random");
             this.add(button);
             button.addActionListener(this);
             text = new TextField("",50);
             this.add(text);
             
             this.setVisible(true);
        }
        
        public void actionPerformed(ActionEvent e)
        {
         int[] value = randoms();
         String temp = "";
         for(int i=0;i<22;i++)
         temp+=(value[i]+" ");
         text.setText(temp);
        }
        
        public static int[] randoms()
    {
    Random r = new Random();

    int temp1,temp2;
    int send[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21};
    int len = send.length;
    int returnValue[] = new int[22];
    for(int i=0;i<22;i++)
    {
    temp1 = Math.abs(r.nextInt())% len;
    returnValue[i] = send[temp1];
    temp2 = send[temp1];
    send[temp1] = send[len-1];
    send[len-1] = temp2;
    len--;
    }
    return returnValue;
    }

    public static void main(String[] args)
    {

    new Text();
    }
    }
      

  7.   

    一个简单的可以显示五次结果的:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Random;public class Test extends Frame {    public static void main(String[] args) {
            final Label[] labels = new Label[]{new Label(), new Label(), new Label(), new Label(), new Label()};
            Button button = new Button("5 times");
            button.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {
                    for (int i = 0; i < 5; i++) {
                        int[] result = randoms();
                        StringBuilder builder = new StringBuilder(i+1+":");
                        for (int j = 0; j < result.length; j++) {
                            builder.append(String.valueOf(result[j]) + "  ");
                        }
                        labels[i].setText(builder.toString());
                    }
                }
            });
            final Frame myFrame = new Frame("Test");
            Panel panel = new Panel(new GridLayout(6, 1));
            panel.add(button);
            for (int i = 0; i < 5; i++) {
                panel.add(labels[i], BorderLayout.CENTER);
            }
            myFrame.add(panel);
            myFrame.pack();
            myFrame.setSize(500, 300);
            myFrame.setVisible(true);
            myFrame.addWindowListener(new WindowAdapter() {            @Override
                public void windowClosing(WindowEvent e) {
                    myFrame.setVisible(false);
                    System.exit(0);
                }
            });
        }    public static int[] randoms() {
            Random r = new Random();        int temp1, temp2;
            int send[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21};
            int len = send.length;
            int returnValue[] = new int[22];
            for (int i = 0; i < 22; i++) {
                temp1 = Math.abs(r.nextInt()) % len;
                returnValue[i] = send[temp1];
                temp2 = send[temp1];
                send[temp1] = send[len - 1];
                send[len - 1] = temp2;
                len--;
            }
            return returnValue;
        }
    }       
      

  8.   

    public class ghfgh {
    public static int[] randoms() {
    Random r = new Random(); int temp1, temp2;
    int send[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
    16, 17, 18, 19, 20, 21 };
    int len = send.length;
    int returnValue[] = new int[22];
    for (int i = 0; i < 22; i++) {
    temp1 = Math.abs(r.nextInt()) % len;
    returnValue[i] = send[temp1];
    temp2 = send[temp1];
    send[temp1] = send[len - 1];
    send[len - 1] = temp2;
    len--;
    }
    return returnValue;
    } public static void main(String[] args) {
    int[] a = new ghfgh().randoms();
    for (int i : a) {
    System.out.println(i);
    }

    }
    }
      

  9.   

    顶,CSDN的分又不是工资。来发贴请教问题,什么叫“请教”?这种帖子坚决不回答。
      

  10.   

    功能基本上就是实现了对一个给定数组随机排序的功能吧。编码的格式实在是ugly...
    import java.util.Random;public class TestRandom {
    public static void main (String args[]){
    int[] random = randoms();

    for (int i=0; i<random.length; i++)
    System.out.print(random[i] +" " );
    }

    public static int[] randoms(){
    Random r = new Random(); int temp1,temp2;
    int send[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21};
    int len = send.length;
    int returnValue[] = new int[22];

    for(int i=0;i<22;i++){
    temp1 = Math.abs(r.nextInt())% len;
    returnValue[i] = send[temp1];
    temp2 = send[temp1];
    send[temp1] = send[len-1];
    send[len-1] = temp2;
    len--;
    }
    return returnValue;
    }
    }
    每次运行的结果都不一样。我这儿运行一次的结果:0 1 5 4 3 2 18 16 15 10 12 14 11 13 17 8 9 7 6 20 21 19 
      

  11.   

    好霸道的语气啊
    LZ
    小心被CSDN排斥