已知鸡兔共35只,共94条腿,求鸡和兔分别多少只?
package chapter02;
public class example18 {
public static void main(String[] args) {
for(int j=0,t=35;j<=35;j++,t--){
if(j * 2 + t * 4 == 94){
System.out.println("鸡:" + + j + ",兔:" + t);
}
}
}
}
上例使用穷举法,下图为运行结果。