Java基础练习题:百元买百鸡

一百块钱买一百只鸡:
公鸡五块一只
母鸡三块一只
小鸡一块三只

公鸡、母鸡、小鸡各多少只?
5x + 3y + z/3 == 100;
x + y + z ==100;

0<= x <=20;
0<= y <=33;
0<= z <=100;

public class Test1 {
	public static void main(String[] args) {

		for (int x = 0; x <= 20; x++) {
			for (int y = 0; y <= 33; y++) {
				int z = 100 - x - y;
				if (z % 3 == 0 && 5 * x + 3 * y + z / 3 == 100) {
					System.out.println("公鸡:" + x + ",  母鸡" + y + ", 小鸡" + z);
				}
			}
		}

	}
}

你可能感兴趣的:(Java)