maees在啊~分不够我可以加啊~我是昨天的andypeng
解决方案 »
- js for循环问题...
- jquery+struts2+spring框架搭建问题,大侠们帮忙看看
- oracle的管理工具,用哪个好?
- HIBERNATE如何映射系统表?
- 有关spring的
- 急!!!用jxl读取excel报错
- weblogic9.1 HelloWorld 求教
- 高分请教在JbuilderX中使用CrystalReportViewer出现Error finding JNDI name的问题
- 请教关于Weblogic部署一个websocket小实例,无法建立连接的问题
- rabbitmq 手动取消消费者注册报错:java.io.IOException: Unknown consumerTag
- java 中面板切换问题???
- 关于spring和Hibernate的使用范围
不能全靠别人啊。否则学不到东西。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();
}
}
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