鹅蛋最多15个,鸭蛋最多34个。public class egg { public static void main(String[] args) { for (int x = 0; x < 16; x++) { for (int y = 0; y < 35; y++) { int z = 100 - x - y; if (z % 7 != 0) continue; if ((7 * x + 3 * y + z / 7) == 100) System.out.println("x=" + x + ";y=" + y + ";z=" + z); } } } }
大概地看了一下第一个回答,思路很清晰,就是感觉如果不是100,而是10000甚至更大的话,就可能要运行上好一段时间了,于是自己写了一段代码,算是优化吧,不好地地方多多指出 public class BuyEgg { public static void main(String[] args) { for(int i = 0; i <= 100/7; i++) { for( int j = 0; j <= (100-7*i)/3; j++) { int tmp = (100-7*i-3*j)*7; //在前面两种蛋确定的基础上,第三种蛋的个数也是唯一确定的. if(i+j+tmp == 100) { System.out.println("三个数分别为: " + i +" " + j + " " + tmp); } } } } }
<code> int count=0; for (int i = 0; i < 15; i++) { for (int j = 0; j <= (100 - 7 * i) / 3; j++) { for (int k = 0; k <= (100 - 7 * i - 3 * j); k++) { count++; if ((i + j + k) == 100) System.out.println(i + "*7+" + j + "*3+" + k + "*1"); } } } System.out.println(count); </code> 运行9440次。。 只得出0*7+0*3+100*1 这个一个结果
public class Test11 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int x; // 鹅蛋个数 int y; //鸭蛋个数 int z; //鸡蛋个数
int totalMoney = 100; // 总钱数 int totalEgg = 100; // 数蛋数
int xPrince = 7; // 鹅蛋价格 int yPrince = 3; // 鸭蛋价格
for (x = 0; x < (totalMoney / xPrince); x++) { for (y = 0; y < (totalMoney - (xPrince * x)) / yPrince; y++) { z = totalEgg - x - y; if (z % 7 == 0) { if ((xPrince * x + yPrince * y + (z / 7)) == totalMoney) { System.out.println("鹅蛋:" + x + "个, " + "鸭蛋:" + y + "个, " + "鸡蛋:" + z + "个"); } } } } }} 输出结果: 鹅蛋:0个, 鸭蛋:30个, 鸡蛋:70个 鹅蛋:5个, 鸭蛋:18个, 鸡蛋:77个 鹅蛋:10个, 鸭蛋:6个, 鸡蛋:84个
/** * *//** * @author JAce * */ public class supererbuer { /** * @param args */ public static void main(String[] args) { /* TODO Auto-generated method stub one goose egg is 7$,one duck egg is 3$,one hen egg is 1/7$ you have one hundred dollars 7g+3d+h/7=100, also h mode 7 should be 0 ask how much is g & d & h */ for (int ge=0;ge<=100;ge++) for (int de=0;de<=100;de++) for (int he=0;he<=100;he++) { if ((he%7==0) && (ge*7+de*3+he/7==100) && (ge+de+he==100) ) { System.out.println ("gosse eggs are"+ge+" duck eggs are "+de+" hen eggs are"+he);
public static void main(String args[]){
for(int x=0; x<=100; x++)
for(int y=0; y<=100; y++)
for(int z=0; z<=100; z++)
if ((z%7 == 0)&&(7*x+3*y+z/7 == 100)&&(x+y+z == 100)){
System.out.println(x +" "+ y +" "+ z);
}
}
}
0 30 70
5 18 77
10 6 84
public class BuyEggs {
public static void main(String args[]){
for(int x=0; x<=100; x++)
for(int y=0; y<=100; y++){
int z = 100-x-y;
if ((z%7 == 0)&&(7*x+3*y+z/7 == 100)){
System.out.println(x +" "+ y +" "+ z);
}
}
}
}
0 30 70
5 18 77
10 6 84
public static void main(String[] args) {
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 35; y++) {
int z = 100 - x - y;
if (z % 7 != 0)
continue;
if ((7 * x + 3 * y + z / 7) == 100)
System.out.println("x=" + x + ";y=" + y + ";z=" + z); }
}
}
}
public class BuyEgg {
public static void main(String[] args) {
for(int i = 0; i <= 100/7; i++) {
for( int j = 0; j <= (100-7*i)/3; j++) {
int tmp = (100-7*i-3*j)*7; //在前面两种蛋确定的基础上,第三种蛋的个数也是唯一确定的.
if(i+j+tmp == 100) {
System.out.println("三个数分别为: " + i +" " + j + " " + tmp);
}
}
}
}
}
//代码
public class EggTest { public static void main(String[] args) {
// TODO Auto-generated method stub
for(int i=0;i<=100;i++){
for(int j=0;j<=(100-i)/3;j++){
for(int k=0;k<=(100-i-3*j);k++){
if((i+3*j+7*k)==100){
System.out.println("鸡蛋 : "+i+"个 鸭蛋 : "+j+"个 鹅蛋 : "+k+"个");
}
}
}
}
}
}
//运行结果:
鸡蛋 : 0个 鸭蛋 : 3个 鹅蛋 : 13个
鸡蛋 : 0个 鸭蛋 : 10个 鹅蛋 : 10个
鸡蛋 : 0个 鸭蛋 : 17个 鹅蛋 : 7个
鸡蛋 : 0个 鸭蛋 : 24个 鹅蛋 : 4个
鸡蛋 : 0个 鸭蛋 : 31个 鹅蛋 : 1个
鸡蛋 : 1个 鸭蛋 : 5个 鹅蛋 : 12个
鸡蛋 : 1个 鸭蛋 : 12个 鹅蛋 : 9个
鸡蛋 : 1个 鸭蛋 : 19个 鹅蛋 : 6个
鸡蛋 : 1个 鸭蛋 : 26个 鹅蛋 : 3个
鸡蛋 : 1个 鸭蛋 : 33个 鹅蛋 : 0个
鸡蛋 : 2个 鸭蛋 : 0个 鹅蛋 : 14个
鸡蛋 : 2个 鸭蛋 : 7个 鹅蛋 : 11个
鸡蛋 : 2个 鸭蛋 : 14个 鹅蛋 : 8个
鸡蛋 : 2个 鸭蛋 : 21个 鹅蛋 : 5个
鸡蛋 : 2个 鸭蛋 : 28个 鹅蛋 : 2个
鸡蛋 : 3个 鸭蛋 : 2个 鹅蛋 : 13个
鸡蛋 : 3个 鸭蛋 : 9个 鹅蛋 : 10个
鸡蛋 : 3个 鸭蛋 : 16个 鹅蛋 : 7个
鸡蛋 : 3个 鸭蛋 : 23个 鹅蛋 : 4个
鸡蛋 : 3个 鸭蛋 : 30个 鹅蛋 : 1个
鸡蛋 : 4个 鸭蛋 : 4个 鹅蛋 : 12个
鸡蛋 : 4个 鸭蛋 : 11个 鹅蛋 : 9个
鸡蛋 : 4个 鸭蛋 : 18个 鹅蛋 : 6个
鸡蛋 : 4个 鸭蛋 : 25个 鹅蛋 : 3个
鸡蛋 : 4个 鸭蛋 : 32个 鹅蛋 : 0个
鸡蛋 : 5个 鸭蛋 : 6个 鹅蛋 : 11个
鸡蛋 : 5个 鸭蛋 : 13个 鹅蛋 : 8个
鸡蛋 : 5个 鸭蛋 : 20个 鹅蛋 : 5个
鸡蛋 : 5个 鸭蛋 : 27个 鹅蛋 : 2个
鸡蛋 : 6个 鸭蛋 : 1个 鹅蛋 : 13个
鸡蛋 : 6个 鸭蛋 : 8个 鹅蛋 : 10个
鸡蛋 : 6个 鸭蛋 : 15个 鹅蛋 : 7个
鸡蛋 : 6个 鸭蛋 : 22个 鹅蛋 : 4个
鸡蛋 : 6个 鸭蛋 : 29个 鹅蛋 : 1个
鸡蛋 : 7个 鸭蛋 : 3个 鹅蛋 : 12个
鸡蛋 : 7个 鸭蛋 : 10个 鹅蛋 : 9个
鸡蛋 : 7个 鸭蛋 : 17个 鹅蛋 : 6个
鸡蛋 : 7个 鸭蛋 : 24个 鹅蛋 : 3个
鸡蛋 : 7个 鸭蛋 : 31个 鹅蛋 : 0个
鸡蛋 : 8个 鸭蛋 : 5个 鹅蛋 : 11个
鸡蛋 : 8个 鸭蛋 : 12个 鹅蛋 : 8个
鸡蛋 : 8个 鸭蛋 : 19个 鹅蛋 : 5个
鸡蛋 : 8个 鸭蛋 : 26个 鹅蛋 : 2个
鸡蛋 : 9个 鸭蛋 : 0个 鹅蛋 : 13个
鸡蛋 : 9个 鸭蛋 : 7个 鹅蛋 : 10个
鸡蛋 : 9个 鸭蛋 : 14个 鹅蛋 : 7个
鸡蛋 : 9个 鸭蛋 : 21个 鹅蛋 : 4个
鸡蛋 : 9个 鸭蛋 : 28个 鹅蛋 : 1个
鸡蛋 : 10个 鸭蛋 : 2个 鹅蛋 : 12个
鸡蛋 : 10个 鸭蛋 : 9个 鹅蛋 : 9个
鸡蛋 : 10个 鸭蛋 : 16个 鹅蛋 : 6个
鸡蛋 : 10个 鸭蛋 : 23个 鹅蛋 : 3个
鸡蛋 : 10个 鸭蛋 : 30个 鹅蛋 : 0个
鸡蛋 : 11个 鸭蛋 : 4个 鹅蛋 : 11个
鸡蛋 : 11个 鸭蛋 : 11个 鹅蛋 : 8个
鸡蛋 : 11个 鸭蛋 : 18个 鹅蛋 : 5个
鸡蛋 : 11个 鸭蛋 : 25个 鹅蛋 : 2个
鸡蛋 : 12个 鸭蛋 : 6个 鹅蛋 : 10个
鸡蛋 : 12个 鸭蛋 : 13个 鹅蛋 : 7个
鸡蛋 : 12个 鸭蛋 : 20个 鹅蛋 : 4个
鸡蛋 : 12个 鸭蛋 : 27个 鹅蛋 : 1个
鸡蛋 : 13个 鸭蛋 : 1个 鹅蛋 : 12个
鸡蛋 : 13个 鸭蛋 : 8个 鹅蛋 : 9个
鸡蛋 : 13个 鸭蛋 : 15个 鹅蛋 : 6个
鸡蛋 : 13个 鸭蛋 : 22个 鹅蛋 : 3个
鸡蛋 : 13个 鸭蛋 : 29个 鹅蛋 : 0个
鸡蛋 : 14个 鸭蛋 : 3个 鹅蛋 : 11个
鸡蛋 : 14个 鸭蛋 : 10个 鹅蛋 : 8个
鸡蛋 : 14个 鸭蛋 : 17个 鹅蛋 : 5个
鸡蛋 : 14个 鸭蛋 : 24个 鹅蛋 : 2个
鸡蛋 : 15个 鸭蛋 : 5个 鹅蛋 : 10个
鸡蛋 : 15个 鸭蛋 : 12个 鹅蛋 : 7个
鸡蛋 : 15个 鸭蛋 : 19个 鹅蛋 : 4个
鸡蛋 : 15个 鸭蛋 : 26个 鹅蛋 : 1个
鸡蛋 : 16个 鸭蛋 : 0个 鹅蛋 : 12个
鸡蛋 : 16个 鸭蛋 : 7个 鹅蛋 : 9个
鸡蛋 : 16个 鸭蛋 : 14个 鹅蛋 : 6个
鸡蛋 : 16个 鸭蛋 : 21个 鹅蛋 : 3个
鸡蛋 : 16个 鸭蛋 : 28个 鹅蛋 : 0个
鸡蛋 : 17个 鸭蛋 : 2个 鹅蛋 : 11个
鸡蛋 : 17个 鸭蛋 : 9个 鹅蛋 : 8个
鸡蛋 : 17个 鸭蛋 : 16个 鹅蛋 : 5个
鸡蛋 : 17个 鸭蛋 : 23个 鹅蛋 : 2个
鸡蛋 : 18个 鸭蛋 : 4个 鹅蛋 : 10个
鸡蛋 : 18个 鸭蛋 : 11个 鹅蛋 : 7个
鸡蛋 : 18个 鸭蛋 : 18个 鹅蛋 : 4个
鸡蛋 : 18个 鸭蛋 : 25个 鹅蛋 : 1个
鸡蛋 : 19个 鸭蛋 : 6个 鹅蛋 : 9个
鸡蛋 : 19个 鸭蛋 : 13个 鹅蛋 : 6个
鸡蛋 : 19个 鸭蛋 : 20个 鹅蛋 : 3个
鸡蛋 : 19个 鸭蛋 : 27个 鹅蛋 : 0个
鸡蛋 : 20个 鸭蛋 : 1个 鹅蛋 : 11个
鸡蛋 : 20个 鸭蛋 : 8个 鹅蛋 : 8个
鸡蛋 : 20个 鸭蛋 : 15个 鹅蛋 : 5个
鸡蛋 : 20个 鸭蛋 : 22个 鹅蛋 : 2个
鸡蛋 : 21个 鸭蛋 : 3个 鹅蛋 : 10个
鸡蛋 : 21个 鸭蛋 : 10个 鹅蛋 : 7个
鸡蛋 : 21个 鸭蛋 : 17个 鹅蛋 : 4个
鸡蛋 : 21个 鸭蛋 : 24个 鹅蛋 : 1个
鸡蛋 : 22个 鸭蛋 : 5个 鹅蛋 : 9个
鸡蛋 : 22个 鸭蛋 : 12个 鹅蛋 : 6个
鸡蛋 : 22个 鸭蛋 : 19个 鹅蛋 : 3个
鸡蛋 : 22个 鸭蛋 : 26个 鹅蛋 : 0个
鸡蛋 : 23个 鸭蛋 : 0个 鹅蛋 : 11个
鸡蛋 : 23个 鸭蛋 : 7个 鹅蛋 : 8个
鸡蛋 : 23个 鸭蛋 : 14个 鹅蛋 : 5个
鸡蛋 : 23个 鸭蛋 : 21个 鹅蛋 : 2个
鸡蛋 : 24个 鸭蛋 : 2个 鹅蛋 : 10个
鸡蛋 : 24个 鸭蛋 : 9个 鹅蛋 : 7个
鸡蛋 : 24个 鸭蛋 : 16个 鹅蛋 : 4个
鸡蛋 : 24个 鸭蛋 : 23个 鹅蛋 : 1个
鸡蛋 : 25个 鸭蛋 : 4个 鹅蛋 : 9个
鸡蛋 : 25个 鸭蛋 : 11个 鹅蛋 : 6个
鸡蛋 : 25个 鸭蛋 : 18个 鹅蛋 : 3个
鸡蛋 : 25个 鸭蛋 : 25个 鹅蛋 : 0个
鸡蛋 : 26个 鸭蛋 : 6个 鹅蛋 : 8个
鸡蛋 : 26个 鸭蛋 : 13个 鹅蛋 : 5个
鸡蛋 : 26个 鸭蛋 : 20个 鹅蛋 : 2个
鸡蛋 : 27个 鸭蛋 : 1个 鹅蛋 : 10个
鸡蛋 : 27个 鸭蛋 : 8个 鹅蛋 : 7个
鸡蛋 : 27个 鸭蛋 : 15个 鹅蛋 : 4个
鸡蛋 : 27个 鸭蛋 : 22个 鹅蛋 : 1个
鸡蛋 : 28个 鸭蛋 : 3个 鹅蛋 : 9个
鸡蛋 : 28个 鸭蛋 : 10个 鹅蛋 : 6个
鸡蛋 : 28个 鸭蛋 : 17个 鹅蛋 : 3个
鸡蛋 : 28个 鸭蛋 : 24个 鹅蛋 : 0个
鸡蛋 : 29个 鸭蛋 : 5个 鹅蛋 : 8个
鸡蛋 : 29个 鸭蛋 : 12个 鹅蛋 : 5个
鸡蛋 : 29个 鸭蛋 : 19个 鹅蛋 : 2个
鸡蛋 : 30个 鸭蛋 : 0个 鹅蛋 : 10个
鸡蛋 : 30个 鸭蛋 : 7个 鹅蛋 : 7个
鸡蛋 : 30个 鸭蛋 : 14个 鹅蛋 : 4个
鸡蛋 : 30个 鸭蛋 : 21个 鹅蛋 : 1个
鸡蛋 : 31个 鸭蛋 : 2个 鹅蛋 : 9个
鸡蛋 : 31个 鸭蛋 : 9个 鹅蛋 : 6个
鸡蛋 : 31个 鸭蛋 : 16个 鹅蛋 : 3个
鸡蛋 : 31个 鸭蛋 : 23个 鹅蛋 : 0个
鸡蛋 : 32个 鸭蛋 : 4个 鹅蛋 : 8个
鸡蛋 : 32个 鸭蛋 : 11个 鹅蛋 : 5个
鸡蛋 : 32个 鸭蛋 : 18个 鹅蛋 : 2个
鸡蛋 : 33个 鸭蛋 : 6个 鹅蛋 : 7个
鸡蛋 : 33个 鸭蛋 : 13个 鹅蛋 : 4个
鸡蛋 : 33个 鸭蛋 : 20个 鹅蛋 : 1个
鸡蛋 : 34个 鸭蛋 : 1个 鹅蛋 : 9个
鸡蛋 : 34个 鸭蛋 : 8个 鹅蛋 : 6个
鸡蛋 : 34个 鸭蛋 : 15个 鹅蛋 : 3个
鸡蛋 : 34个 鸭蛋 : 22个 鹅蛋 : 0个
鸡蛋 : 35个 鸭蛋 : 3个 鹅蛋 : 8个
鸡蛋 : 35个 鸭蛋 : 10个 鹅蛋 : 5个
鸡蛋 : 35个 鸭蛋 : 17个 鹅蛋 : 2个
鸡蛋 : 36个 鸭蛋 : 5个 鹅蛋 : 7个
鸡蛋 : 36个 鸭蛋 : 12个 鹅蛋 : 4个
鸡蛋 : 36个 鸭蛋 : 19个 鹅蛋 : 1个
鸡蛋 : 37个 鸭蛋 : 0个 鹅蛋 : 9个
鸡蛋 : 37个 鸭蛋 : 7个 鹅蛋 : 6个
鸡蛋 : 37个 鸭蛋 : 14个 鹅蛋 : 3个
鸡蛋 : 37个 鸭蛋 : 21个 鹅蛋 : 0个
鸡蛋 : 38个 鸭蛋 : 2个 鹅蛋 : 8个
鸡蛋 : 38个 鸭蛋 : 9个 鹅蛋 : 5个
鸡蛋 : 38个 鸭蛋 : 16个 鹅蛋 : 2个
鸡蛋 : 39个 鸭蛋 : 4个 鹅蛋 : 7个
鸡蛋 : 39个 鸭蛋 : 11个 鹅蛋 : 4个
鸡蛋 : 39个 鸭蛋 : 18个 鹅蛋 : 1个
鸡蛋 : 40个 鸭蛋 : 6个 鹅蛋 : 6个
鸡蛋 : 40个 鸭蛋 : 13个 鹅蛋 : 3个
鸡蛋 : 40个 鸭蛋 : 20个 鹅蛋 : 0个
鸡蛋 : 41个 鸭蛋 : 1个 鹅蛋 : 8个
鸡蛋 : 41个 鸭蛋 : 8个 鹅蛋 : 5个
鸡蛋 : 41个 鸭蛋 : 15个 鹅蛋 : 2个
鸡蛋 : 42个 鸭蛋 : 3个 鹅蛋 : 7个
鸡蛋 : 42个 鸭蛋 : 10个 鹅蛋 : 4个
鸡蛋 : 42个 鸭蛋 : 17个 鹅蛋 : 1个
鸡蛋 : 43个 鸭蛋 : 5个 鹅蛋 : 6个
鸡蛋 : 43个 鸭蛋 : 12个 鹅蛋 : 3个
鸡蛋 : 43个 鸭蛋 : 19个 鹅蛋 : 0个
鸡蛋 : 44个 鸭蛋 : 0个 鹅蛋 : 8个
鸡蛋 : 44个 鸭蛋 : 7个 鹅蛋 : 5个
鸡蛋 : 44个 鸭蛋 : 14个 鹅蛋 : 2个
鸡蛋 : 45个 鸭蛋 : 2个 鹅蛋 : 7个
鸡蛋 : 45个 鸭蛋 : 9个 鹅蛋 : 4个
鸡蛋 : 45个 鸭蛋 : 16个 鹅蛋 : 1个
鸡蛋 : 46个 鸭蛋 : 4个 鹅蛋 : 6个
鸡蛋 : 46个 鸭蛋 : 11个 鹅蛋 : 3个
鸡蛋 : 46个 鸭蛋 : 18个 鹅蛋 : 0个
鸡蛋 : 47个 鸭蛋 : 6个 鹅蛋 : 5个
鸡蛋 : 47个 鸭蛋 : 13个 鹅蛋 : 2个
鸡蛋 : 48个 鸭蛋 : 1个 鹅蛋 : 7个
鸡蛋 : 48个 鸭蛋 : 8个 鹅蛋 : 4个
鸡蛋 : 48个 鸭蛋 : 15个 鹅蛋 : 1个
鸡蛋 : 49个 鸭蛋 : 3个 鹅蛋 : 6个
鸡蛋 : 49个 鸭蛋 : 10个 鹅蛋 : 3个
鸡蛋 : 49个 鸭蛋 : 17个 鹅蛋 : 0个
鸡蛋 : 50个 鸭蛋 : 5个 鹅蛋 : 5个
鸡蛋 : 50个 鸭蛋 : 12个 鹅蛋 : 2个
鸡蛋 : 51个 鸭蛋 : 0个 鹅蛋 : 7个
鸡蛋 : 51个 鸭蛋 : 7个 鹅蛋 : 4个
鸡蛋 : 51个 鸭蛋 : 14个 鹅蛋 : 1个
鸡蛋 : 52个 鸭蛋 : 2个 鹅蛋 : 6个
鸡蛋 : 52个 鸭蛋 : 9个 鹅蛋 : 3个
鸡蛋 : 52个 鸭蛋 : 16个 鹅蛋 : 0个
鸡蛋 : 53个 鸭蛋 : 4个 鹅蛋 : 5个
鸡蛋 : 53个 鸭蛋 : 11个 鹅蛋 : 2个
鸡蛋 : 54个 鸭蛋 : 6个 鹅蛋 : 4个
鸡蛋 : 54个 鸭蛋 : 13个 鹅蛋 : 1个
鸡蛋 : 55个 鸭蛋 : 1个 鹅蛋 : 6个
鸡蛋 : 55个 鸭蛋 : 8个 鹅蛋 : 3个
鸡蛋 : 55个 鸭蛋 : 15个 鹅蛋 : 0个
鸡蛋 : 56个 鸭蛋 : 3个 鹅蛋 : 5个
鸡蛋 : 56个 鸭蛋 : 10个 鹅蛋 : 2个
鸡蛋 : 57个 鸭蛋 : 5个 鹅蛋 : 4个
鸡蛋 : 57个 鸭蛋 : 12个 鹅蛋 : 1个
鸡蛋 : 58个 鸭蛋 : 0个 鹅蛋 : 6个
鸡蛋 : 58个 鸭蛋 : 7个 鹅蛋 : 3个
鸡蛋 : 58个 鸭蛋 : 14个 鹅蛋 : 0个
鸡蛋 : 59个 鸭蛋 : 2个 鹅蛋 : 5个
鸡蛋 : 59个 鸭蛋 : 9个 鹅蛋 : 2个
鸡蛋 : 60个 鸭蛋 : 4个 鹅蛋 : 4个
鸡蛋 : 60个 鸭蛋 : 11个 鹅蛋 : 1个
鸡蛋 : 61个 鸭蛋 : 6个 鹅蛋 : 3个
鸡蛋 : 61个 鸭蛋 : 13个 鹅蛋 : 0个
鸡蛋 : 62个 鸭蛋 : 1个 鹅蛋 : 5个
鸡蛋 : 62个 鸭蛋 : 8个 鹅蛋 : 2个
鸡蛋 : 63个 鸭蛋 : 3个 鹅蛋 : 4个
鸡蛋 : 63个 鸭蛋 : 10个 鹅蛋 : 1个
鸡蛋 : 64个 鸭蛋 : 5个 鹅蛋 : 3个
鸡蛋 : 64个 鸭蛋 : 12个 鹅蛋 : 0个
鸡蛋 : 65个 鸭蛋 : 0个 鹅蛋 : 5个
鸡蛋 : 65个 鸭蛋 : 7个 鹅蛋 : 2个
鸡蛋 : 66个 鸭蛋 : 2个 鹅蛋 : 4个
鸡蛋 : 66个 鸭蛋 : 9个 鹅蛋 : 1个
鸡蛋 : 67个 鸭蛋 : 4个 鹅蛋 : 3个
鸡蛋 : 67个 鸭蛋 : 11个 鹅蛋 : 0个
鸡蛋 : 68个 鸭蛋 : 6个 鹅蛋 : 2个
鸡蛋 : 69个 鸭蛋 : 1个 鹅蛋 : 4个
鸡蛋 : 69个 鸭蛋 : 8个 鹅蛋 : 1个
鸡蛋 : 70个 鸭蛋 : 3个 鹅蛋 : 3个
鸡蛋 : 70个 鸭蛋 : 10个 鹅蛋 : 0个
鸡蛋 : 71个 鸭蛋 : 5个 鹅蛋 : 2个
鸡蛋 : 72个 鸭蛋 : 0个 鹅蛋 : 4个
鸡蛋 : 72个 鸭蛋 : 7个 鹅蛋 : 1个
鸡蛋 : 73个 鸭蛋 : 2个 鹅蛋 : 3个
鸡蛋 : 73个 鸭蛋 : 9个 鹅蛋 : 0个
鸡蛋 : 74个 鸭蛋 : 4个 鹅蛋 : 2个
鸡蛋 : 75个 鸭蛋 : 6个 鹅蛋 : 1个
鸡蛋 : 76个 鸭蛋 : 1个 鹅蛋 : 3个
鸡蛋 : 76个 鸭蛋 : 8个 鹅蛋 : 0个
鸡蛋 : 77个 鸭蛋 : 3个 鹅蛋 : 2个
鸡蛋 : 78个 鸭蛋 : 5个 鹅蛋 : 1个
鸡蛋 : 79个 鸭蛋 : 0个 鹅蛋 : 3个
鸡蛋 : 79个 鸭蛋 : 7个 鹅蛋 : 0个
鸡蛋 : 80个 鸭蛋 : 2个 鹅蛋 : 2个
鸡蛋 : 81个 鸭蛋 : 4个 鹅蛋 : 1个
鸡蛋 : 82个 鸭蛋 : 6个 鹅蛋 : 0个
鸡蛋 : 83个 鸭蛋 : 1个 鹅蛋 : 2个
鸡蛋 : 84个 鸭蛋 : 3个 鹅蛋 : 1个
鸡蛋 : 85个 鸭蛋 : 5个 鹅蛋 : 0个
鸡蛋 : 86个 鸭蛋 : 0个 鹅蛋 : 2个
鸡蛋 : 87个 鸭蛋 : 2个 鹅蛋 : 1个
鸡蛋 : 88个 鸭蛋 : 4个 鹅蛋 : 0个
鸡蛋 : 90个 鸭蛋 : 1个 鹅蛋 : 1个
鸡蛋 : 91个 鸭蛋 : 3个 鹅蛋 : 0个
鸡蛋 : 93个 鸭蛋 : 0个 鹅蛋 : 1个
鸡蛋 : 94个 鸭蛋 : 2个 鹅蛋 : 0个
鸡蛋 : 97个 鸭蛋 : 1个 鹅蛋 : 0个
鸡蛋 : 100个 鸭蛋 : 0个 鹅蛋 : 0个
int count=0;
for (int i = 0; i < 15; i++) {
for (int j = 0; j <= (100 - 7 * i) / 3; j++) {
for (int k = 0; k <= (100 - 7 * i - 3 * j); k++) {
count++;
if ((i + j + k) == 100)
System.out.println(i + "*7+" + j + "*3+" + k + "*1");
}
}
}
System.out.println(count);
</code>
运行9440次。。
只得出0*7+0*3+100*1
这个一个结果
public class Test11 { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub int x; // 鹅蛋个数
int y; //鸭蛋个数
int z; //鸡蛋个数
int totalMoney = 100; // 总钱数
int totalEgg = 100; // 数蛋数
int xPrince = 7; // 鹅蛋价格
int yPrince = 3; // 鸭蛋价格
for (x = 0; x < (totalMoney / xPrince); x++) {
for (y = 0; y < (totalMoney - (xPrince * x)) / yPrince; y++) {
z = totalEgg - x - y;
if (z % 7 == 0) {
if ((xPrince * x + yPrince * y + (z / 7)) == totalMoney) {
System.out.println("鹅蛋:" + x + "个, " + "鸭蛋:" + y + "个, " + "鸡蛋:" + z + "个");
}
}
}
}
}}
输出结果:
鹅蛋:0个, 鸭蛋:30个, 鸡蛋:70个
鹅蛋:5个, 鸭蛋:18个, 鸡蛋:77个
鹅蛋:10个, 鸭蛋:6个, 鸡蛋:84个
*
*//**
* @author JAce
*
*/
public class supererbuer { /**
* @param args
*/
public static void main(String[] args) {
/* TODO Auto-generated method stub
one goose egg is 7$,one duck egg is 3$,one hen egg is 1/7$
you have one hundred dollars
7g+3d+h/7=100, also h mode 7 should be 0
ask how much is g & d & h */
for (int ge=0;ge<=100;ge++)
for (int de=0;de<=100;de++)
for (int he=0;he<=100;he++)
{
if ((he%7==0) && (ge*7+de*3+he/7==100) && (ge+de+he==100) )
{
System.out.println ("gosse eggs are"+ge+" duck eggs are "+de+" hen eggs are"+he);
}
}
}}