/* * 一只公鸡五元,一只母鸡三元,三只小鸡一元钱 * 要求100元买100只鸡,问一共有多少种买法 * */ public class ForDemo2 { public static void main(String[] args) { // TODO Auto-generated method stub int gj; int mj; int xj; int count=0; for(gj=0;gj<=20;gj++) { for(mj=0;mj<=33;mj++) { for(xj=0;xj<=100;xj++) { if(xj%3==0) { if((gj+mj+xj==100)&&(gj*5+mj*3+xj/3==100)) { count++; System.out.println("公鸡:"+gj+"只,母鸡:"+mj+"只,小鸡:"+xj+"只"); } } } } } System.out.println("一共"+count+"种买法"); } }