统计信息

  • 访问数:6141
  • 博客数:141
  • 建立时间:2008-01-05
  • 更新时间:2008-05-09
我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!

AssignSeats

2008-05-09 08:42:35

天气: 晴朗 心情: 高兴

/* Write a program which randomly assign 30 Computing students to their
 * common test seats using a 2D array
 *
CHUA WEE KIAT MERVYN
FOO HEE WEI GARY
GERALDINE TAY HUI LING
GOH SHUN JIE
HO KOK CHING HSIEN
HO SIMIN
HONG SHI KAI SEBASTIAN
JONATHAN SUNG LI JIE
KENNETH KOW WEI SUAN
KOH KEITH
LEE YAN
LEE YU LING ESTHER
LIM MIAO JIN GRACE
LIM TING WEI THADDEUS
MAI HONG YI
NG CHING SIANG
NG WEI JIE
NG XIN YI
ONG CI HUI AGNES
ONG GUO XIANG
ONG YUAN XIANG JEROME
POH YONG CHIANG
SONG XIAOTIAN
WANG CHAORAN
WANG YIGENG
WU SHITONG
WUU JASVIN
XU ZIJIA
YAP QUAN YI
ZEE KIN MENG ANDREW
 */

public class AssignSeats {
  public static void main(String args[]) {
 
    // Declare constants
    final int NUM_STUDENTS = 30;
   
    // Declare variables
    int[][] seat = new int[4][8];
    seat[(int)(Math.random()*4)][(int)(Math.random()*8)]=1;
    for(int i=2;i<31;i++){
    boolean judge = true;
    while(judge){
      int row = (int)(Math.random()*4);
      int column = (int)(Math.random()*8);
      if(seat[row][column]==0){
      judge=false;
      seat[row][column]=i;
      }
    }
  }
   for(int i=0;i<seat.length;i++){
     for(int j=0;j<seat[i].length;j++){
       if((seat[i][j]==0)&&(seat[seat.length-1][seat[i].length-1]!=0)){
        int temp = seat[i][j];
        seat[i][j] = seat[seat.length-1][seat[i].length-1];
        seat[seat.length-1][seat[i].length-1] = temp;
       }
       else if(seat[i][j]==0){
         int temp = seat[i][j];
         seat[i][j] = seat[seat.length-1][seat[i].length-2];
         seat[seat.length-1][seat[i].length-2] = temp;
       }
     }
    }

    for(int i=0;i<seat.length;i++){
      for(int j=0;j<seat[i].length;j++)
      System.out.printf("%4d",seat[i][j]);
    System.out.println();
  }
}
}
 


加入收藏 编辑 审核

TAG: computing

我来说两句

OPEN

Powered by X-Space 1.2 © 2001-2006 Comsenz Technology Ltd