maees在啊~分不够我可以加啊~我是昨天的andypeng

解决方案 »

  1.   

    最好能用GUI只要装上JAVA虚拟机就能运行的~~~其他的也行~麻烦您了
      

  2.   

    gui麻烦得很,随便写了一个命令行的,自己看着改吧。
    不能全靠别人啊。否则学不到东西。import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    import java.util.Random;public class Demo {
        
        /** Creates a new instance of Demo */
        public Demo() {
        }
        
        public static Random random = new Random();
        
        public  static   void action(String[] room,String[] std)throws Exception{
            // 选择教室
            String[] sr = new String[2];
            sr[0] = room[random.nextInt(room.length)];
            while(true){
                sr[1] = room[random.nextInt(room.length)];
                if(!sr[1].equals(sr[0])){
                    break;
                }
            }
            System.out.println("选择的教室是:"+sr[0]+","+sr[1]);
            // 两个教室分配的学生
            String[] std1 = new String[30];
            String[] std2 = new String[30];
            
            // 已经被选择的学生
            List list = new ArrayList(Arrays.asList(std));
            for (int i = 0; i<30 ; i++) {
                String str = (String)list.get(random.nextInt(list.size()));
                std1[i] = str;
                list.remove(str);
            }
            for (int i = 0; i<30 ; i++) {
                String str = (String)list.get(random.nextInt(list.size()));
                std2[i] = str;
                list.remove(str);
            }
            
            System.out.println("第一间教室"+sr[0]+":");
            for (int i = 0; i < std1.length; i++) {
                System.out.print(std1[i]+",");
            }
            System.out.println("");
            System.out.println("第二间教室"+sr[1]+":");
            for (int i = 0; i < std2.length; i++) {
                System.out.print(std2[i]+",");
            }
        }
        
        public static  void test()throws Exception{
            String[] room = new String[]{"A","B","C","D","E","F","G","H","I","J","K"};
            String[] std =new String[60];
            for (int i = 1; i <=60; i++) {
                std[i-1] = String.valueOf(1000+i).substring(1);
            }
            action(room,std);
        }
        
        public static void input()throws Exception{
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            String[] room = new String[]{"A","B","C","D","E","F","G","H","I","J","K"};
            String[] std =new String[60];
            for (int i = 1; i <=60; i++) {
                str = in.readLine();
                std[i-1]=str;
            }
            action(room,std);
        }
        
        public static void main(String[] args)throws Exception {
    //        test();
            input();
        }
        
    }
      

  3.   

    http://community.csdn.net/Expert/topic/5499/5499682.xml?temp=.3529627你在这个帖子说个话~这是我在GUI区发的问题
      

  4.   

    2个教室和一个教室其实都是一样的,将第一个教室的座位编号为1到30,将第二个教室的座位的编号编为31到60,这样,问题,就变成了60个学生,60个座位,(程序中)然后我们先让学生按顺序坐上去,然后经过一定的调整,就可以达到随机按排座位的效果了
    RadomLocation.java
    =================================
    import java.util.Random;public class RadomLocation {
       
        public static void main(String[] args){
    int[] numArray = new int[60];
    //这里你自己输入60个学号吧,这里我用了int类型,这里设成学号为1到60
    for(int i = 0;i < numArray.length;i++){
        numArray[i] = i + 1;
    }
    System.out.println("调整前");
    printLocation(numArray);
    changeLocation(numArray);
    System.out.println("调整后:");
    printLocation(numArray);
        }
        
        public static void printLocation(int[] numArray){
    for(int i = 0;i < numArray.length;i++){
        System.out.printf("%4d",numArray[i]);
        if((i+1) % 5 == 0)System.out.println();
    }
        }
        
        public static void changeLocation(int[] numArray){
    Random rd = new Random();
    int flag;
    int temp;
    for(int i = 0;i < numArray.length;i++){
        flag = rd.nextInt(numArray.length);
        temp = numArray[i];
        numArray[i] = numArray[flag];
        numArray[flag] = temp;
    }
        }
    }==========================================
    运行结果
    调整前
       1   2   3   4   5
       6   7   8   9  10
      11  12  13  14  15
      16  17  18  19  20
      21  22  23  24  25
      26  27  28  29  30
      31  32  33  34  35
      36  37  38  39  40
      41  42  43  44  45
      46  47  48  49  50
      51  52  53  54  55
      56  57  58  59  60
    调整后:
      21  48   5  15  49
      51  34   3  20  14
       9  11  59   4  45
       8  58  23  37  27
      57  43  16  44  12
      19  39  28  22  35
      26  30  40  47  50
      29  38  33   2  24
      55   1  13  32  53
      52  41  46  10  42
      31  54  25   6  56
      18  60  17  36   7