第1个回答 2007-02-06
package applet_test;
import javax.swing.*;
import java.awt.Container;
public class buy extends JApplet
{
public void init()
{
int a,b;
String output="";
JTextArea outputArea = new JTextArea( 10, 20 );
Container c = getContentPane();
c.add(outputArea);
for(a=1;a<20;a++)
{
for (b=1;b<33;b++)
{
if(a*5+b*3+(100-a-b)/2==100)
{
output+="\n公鸡:"+a+"只 母鸡:"+b+"只 小鸡:"+(100-a-b)+"只";
}
}
}
outputArea.setText( output );
}
}
正好前几天给朋友做过这个.本回答被提问者采纳
第2个回答 2007-02-06
用PASCAL来编
var a,b,c:integer;
begin
for a:=1 to 99 do
for b:=1 to 99 do
for c:=1 to 99 do
begin
if (a+b+c<>100) or (c mod 2<>0) then continue;
if (a*5+b*3+c div 2=100) then writeln(a,' ',b,' ',c);
end;
end.