public class Test2
{
public static void main(String[] args)
{ for(int x=1; x<=30; x++){
for(int y=1;y<=30; y++){
int z=30-x-y;
if(x*3+y*2+z==50)
System.out.println("男"+x+"女"+y+"小孩"+z);
}
}
}
}作者: 今天是坏蛋 时间: 2014-2-19 19:12
果断的3重for循环啊!!class Test { Test() { for (int i = 0;i<30 ;i++ ) { for (int j = 0;j<30 ;j++ ) { for (int k = 0;k<30 ;k++ ) { if (50==i*3+j*2+k*1) { System.out.println("i="+i+",j="+j+",k="+k); } } } } } } class HeiMa { public static void main(String []args) { Test t = new Test(); } }作者: 今天是坏蛋 时间: 2014-2-19 19:21
/*
采用3重for循环,代码更容易理解些,元方你怎么看?
*/
class Test
{
Test()
{
for (int i = 0;i<30 ;i++ )
{
for (int j = 0;j<30 ;j++ )
{
for (int k = 0;k<30 ;k++ )
{
if (50==i*3+j*2+k*1)
{
System.out.println("i="+i+",j="+j+",k="+k);
}
}
}
}
}
}
class HeiMa
{
public static void main(String []args)
{
Test t = new Test();
}
}作者: e.c 时间: 2014-2-19 20:13
for (int x = 1; x <= 50 / 3; x++) {
for (int y = 1; y <= (50 - 3 * x) / 2; y++) {
int z = 30 - x - y;
if ((3 * x + 2 * y + z) == 50) {
System.out.println("男:" + x + "女:" + y + "小孩:" + z);
}