共94只脚,鸡和兔共35只,请问有多少只鸡和兔
package adsf;
public class dst {
public static void main(String[] args) {
int x;
int y;
for(x=0;x<=35;x++) {
for(y=0;y<=35;y++) {
if(x+y==35&&2*x+4*y==94) {
System.out.println("有"+x+"只鸡"+y+"只兔");
break;
}
}
}
}
}
变一下
package adsf;
public class dst {
public static void main(String[] args) {
int x=0;
int y=35-x;
for(x=0;x<=35;x++,y--) {
if(x+y==35&&2*x+4*y==94) {
System.out.println("有"+x+"只鸡"+y+"只兔");
break;
}
}
}
}
再变一下
package adsf;
public class jjjjj {
public static void main(String[] args) {
int jinum;
int tunum;
for(jinum=0;jinum<=35;jinum++) {
tunum=35-jinum;
if(2*jinum+4*tunum==94) {
System.out.println("有"+jinum+"只鸡"+tunum+"只兔");
break;
}
}
}
}