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

题目来源于我国古代数学家张丘建在《算经》一书中提出的数学问题:鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一。百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?

理解有难度,代码没难度

最近边学C++边学Java,这次就用Java来写叭

代码如下:

 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: ★★★★★