A man has a hundred dollars, going to buy one hundred chickens, now the big three dollars a chicken, chicken a dollar three, two dollars a sort of a small chicken. Java programming, just with a one hundred dollars to buy one hundred chickens.

Ideas:

The three chickens from 1 to start for the cycle until you find the number of qualifying all the chickens on the output.

Code:

public class Chicken {
	public static void main(String[] args) {
		int big = 0, modder = 0, xiao = 0;
		for (big = 0; big <= 100; big++) {
			for (modder = 0; modder <= 100; modder++) {
				for (xiao = 0; xiao <= 100; xiao++) {
					if ((3 * big + 2 * modder + xiao / 3) == 100 && (big + modder + xiao) == 100 && xiao % 3 == 0) {
						System.out.println("大鸡"+big+"只");
						System.out.println("不大不小鸡"+modder+"只");
						System.out.println("小鸡"+xiao+"只");
						System.out.println();
					}
				}
			}
		}
	}
}

Run effect diagram:

Published 28 original articles · won praise 5 · Views 5786

Guess you like

Origin blog.csdn.net/weixin_41879980/article/details/100060308