之前学过一点java,最近再看看
- 一、鸡鸭鹅问题
public class Egg { public static void main(String[] args) { int chicken = 0, duck = 0, goose = 0; for( int i = 0; i < 100; i++) { chicken = i; for( int j = 0; j < 100; j++) { duck = j; goose = 100 - duck - chicken; if( chicken + duck * 30 + goose * 60 == 1000 && chicken > 0 && duck > 0 && goose > 0) { System.out.println("鸡:" + chicken + "鸭:" + duck + " 鹅:" + goose); } } } } }
success
这个chicken + duck * 30 + goose * 60 == 1000 为啥称30,乘60,我乘3,乘6等于100不行吗?
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)