
求教2道题!1、用Java做出鸡兔同笼这道数学题!第二题还是数学题!看问题补充,有点长!不要太深奥!
2、一共有30个人,有男,女,小孩,吃饭花了50先令,每个男人花3先令,每个女人花2先令,每个小孩花1先令,男,女,小孩各几人!只学过boolean,if,swich,w...
2、一共有30个人,有男,女,小孩,吃饭花了50先令,每个男人花3先令,每个女人花2先令,每个小孩花1先令,男,女,小孩各几人!
只学过boolean,if,swich,while,do-while,for尽量用这些完成!谢谢!!! 展开
只学过boolean,if,swich,while,do-while,for尽量用这些完成!谢谢!!! 展开
1个回答
展开全部
第二题:
public class Test
{
public static void main(String[] args)
{
int man;
int woman;
int children;
for (man=0;man<50/3;man++)
{
for(woman=0;woman<50/2;woman++)
{
children=30-man-woman;
if(man*3+woman*2+children==50){
System.out.println("男人个数为:"+man);
System.out.println("女人个数为: "+woman);
System.out.println("小孩个数为: "+children);
System.out.println(man+"+"+woman+"+"+children+"="+30);
System.out.println(man+"*"+3+"+"+woman+"*"+2+"+"+children+"*"+1+"="+50);
System.out.println("-------------------");
}
}
}
}
}
public class Test
{
public static void main(String[] args)
{
int man;
int woman;
int children;
for (man=0;man<50/3;man++)
{
for(woman=0;woman<50/2;woman++)
{
children=30-man-woman;
if(man*3+woman*2+children==50){
System.out.println("男人个数为:"+man);
System.out.println("女人个数为: "+woman);
System.out.println("小孩个数为: "+children);
System.out.println(man+"+"+woman+"+"+children+"="+30);
System.out.println(man+"*"+3+"+"+woman+"*"+2+"+"+children+"*"+1+"="+50);
System.out.println("-------------------");
}
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询