已知:韩信点兵,不足百人,3人一行多一人,7人一行少两人,5人一行正好。请问韩信点的兵人数多少?代码实现如下:
package com.itszt.test8;
/**
* 韩信点兵
* a total%3 1
* b total%7 5
* c total%5 0
* total {1,100}
*/
public class Test {
public static void main(String[] args) {
int a,b,c,total;
for(total=1;total<100;total++){
a=total%3;
b=total%7;
c=total%5;
if(a==1 && b==5 && c==0){
System.out.println("韩信点兵的人数是:"+total);
}
}
}
}
运行上述代码,结果如下:
韩信点兵的人数是:40