我们先输入人数
先求出可以分为几组
每组人数大概多少
如果 多人 用余数方式来对每组进行分组输出
public static void main(String[] args) {
Scanner rs = new Scanner(System.in);
int N = rs.nextInt();
int count=1;
double group=Math.ceil(N*1.0/8); //求整分组 ceil是求该小数的上限
int person=N/(int)group; //每组大概多少人
int yu=N%(int)group; //每组多出多少人
for(int j=0;j<yu;j++) //对多出的人先分配
{
System.out.println("第"+count+"组有 "+(person+1)+"人");
count++;
}
for (int i = 0; i < group - yu; i++) //剩下的人分配
{
System.out.println("第"+count+"组有 "+person+"人");
count++;
}
}
运行结果:
