百钱百鸡(A hundred dollars and a hundred chickens)-其他

百钱百鸡(A hundred dollars and a hundred chickens)

public static void main(String[] args) {
int x, y, z, n = 1;
System.out.println("百钱百鸡解法：");
for (x = 0; x <= 20; x++) {
for (y = 0; y <= 33; y++) {
z = 100 - x - y;
if (z % 3 == 0 && 5 * x + 3 * y + z / 3 == 100) {
System.out.println("\t第" + n + "种解法：鸡公" + x + "只，鸡母" + y + "只，鸡雏" + z + "只");
n++;
}
}
}
}

————————

The title comes from the mathematical problem put forward by the ancient mathematician Zhang Qiujian in the book Suanjing: the chicken Weng is worth five, the chicken mother is worth three, and the chicken chick is worth three. If you buy a hundred chickens for a hundred dollars, ask the chicken owner, the chicken mother and the chicken chick?

Understanding is difficult, but the code is not difficult

Recently, I learned Java while learning C + +. This time, I will use java to write ba

The code is as follows:

public static void main(String[] args) {
int x, y, z, n = 1;
System.out.println("百钱百鸡解法：");
for (x = 0; x <= 20; x++) {
for (y = 0; y <= 33; y++) {
z = 100 - x - y;
if (z % 3 == 0 && 5 * x + 3 * y + z / 3 == 100) {
System.out.println("\t第" + n + "种解法：鸡公" + x + "只，鸡母" + y + "只，鸡雏" + z + "只");
n++;
}
}
}
}

Difficulty: ★★★☆☆
Mastery: ★★★★★