java 分班_新生——S型分班算法

该篇博客展示了如何使用Java实现S型分班算法,将学生按特定顺序分配到不同班级。通过一个二维数组存储分班结果,并根据布尔值`order`决定是正序还是倒序排列。代码中定义了一个`DistributeClass`类,包含`divideByClass`方法,用于处理学生的分班逻辑。整个过程包括计算学生的横纵坐标,根据`type`调整班级顺序,最终将结果存入二维数组并打印输出。
摘要由CSDN通过智能技术生成

package org.zttc.service;

public class DistributeClass {

public static final Boolean order =true;

public static void main(String[] args) {

//把分班后数据存入二位数组

int test[][] = divideByClass(64,8,order);

String str = "顺序";

if(!order){

str = "倒序";

}

for(int i=0;i<8;i++){

for(int j=0;j

int x = test[i][j];

if(x != 0){

System.out.println("进行"+str+"排列的结果:第"+(i+1)+"班被分配的第"+(j+1)+"位学生总体排名为:"+x+"");

}

}

}

}

public static int[][] divideByClass(int stuNum,int classNum,boolean type){

//定义一个二维数组,初始化容量为 stuNum=64 classNum=8 ,int[8][9]

int[][] rs = new int[classNum][stuNum/classNum+1];

for(int i=0;i

int x = i%classNum;//求余 64/8 0 1 2 3 4 5 6 7 横坐标

int y = i/classNum;//整除 64/8 0 1 2 3 4 5 6 7 8 纵坐标

//求余x=0,整除y!=0的时候,type取反

if(x==0 && y!=0){ // 8-false 16-true 24-false 32-true 40-false 48-true 56-true 64-false

type=!type;

}

if(!type){

x = classNum-i%classNum-1; //班级数-序号%班级数-1

y = i/classNum;//序号/班级数

}

rs[x][y]=i+1;

/** x求余 y整除 rs数组

* i=0;x=0;y=0;type=true,rs[0][0]=1;

* i=1;x=1;y=0;type=true,rs[1][0]=2;

* i=2;x=2;y=0;type=true,rs[2][0]=3;

* i=3;x=3;y=0;type=true,rs[3][0]=4;

* i=4;x=4;y=0;type=true,rs[4][0]=5;

* i=5;x=5;y=0;type=true,rs[5][0]=6;

* i=6;x=6;y=0;type=true,rs[6][0]=7;

* i=7;x=7;y=0;type=true,rs[7][0]=8;

* i=8;x=6;y=1;type=false,rs[6][1]=9;

* i=9;x=6;y=1;type=false,rs[7][1]=10;

* i=10;x=

*/

}

return rs;

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值