计算男孩女孩小孩各有几个 java——CSDN博客
/** * * @Title: test_men_women_kids * @Description: 该方法的主要作用: * 男人+女人+小孩=30 * 一共花50先令 * 男人:3 女人:2 小孩:1 * @param 设定文件 * @return 返回类型:void * @throws */ @Test public void test_men_women_kids(){ int men = 0; int women = 0; int kids = 0; for (men = 0; men <=10; men++) { women = 20-2*men; kids = 30-men-women; if(3*men+2*women+kids==50){ System.out.println("男人有:"+men+",女人有:"+women+",小孩有:"+kids); } } }