甲乙丙丁四个人加工零件,总数为370个。
如果甲加工的零件数多10个,
如果乙加工的零件数少20个,
如果丙加工的零件数乘以2,
如果丁加工的零件数除以2,
则四人加工的零件数相等。
求四人加工的零件个数分别是多少?
public class TestOne{
public static void main(String[] args){
//定义变量x为四人加工数量相等时的零件数
for(int x=1;x<=370;x++){
if((x-10)+(x+20)+(x*2)+(x/2)==370){
System.out.println("甲加工零件数"+(x-10));
System.out.println("乙加工零件数"+(x+20));
System.out.println("丙加工零件数"+(x/2));
System.out.println("丁加工零件数"+(x*2));
}
}
}
}
优化后的代码
public class TestOne{
public static void main(String[] args){
//通过粗略的计算来确定x的大致范围,提高代码的运行速度
for(int x=