百元买百鸡: 设 花一百元买鸡 公鸡:5元 母鸡:3元 小鸡1元3只
求买鸡的方案
java代码:
import java.util.*; public class helloworld { public static void main(String[] args) { int count=0; for(int i=0;i<20;i++){ for(int j=0;j<34;j++){ for(int z=0;z<300;z=z+3){ if((5*i+3*j+z/3==100)&&(i+j+z==100)){ System.out.println("母鸡:"+i+"公鸡:"+j+"小鸡:"+z); count++; } } } } System.out.println("方案公有:"+count+"种"); } }
效果:
vb.net代码:
Module Module1 Sub Main() Dim count,i,j,k As Integer count = 0 For i = 0 To 20 For j = 0 To 34 For k = 0 To 300 If (((5 * i) + (3 * j) + (k / 3) = 100) And (i + j + k = 100)) Then Console.WriteLine("母鸡:{0}" + "公鸡:{1}" + "小鸡:{2}",k) count = count + 1 End If Next k Next j Next i Console.WriteLine("有{0}种方案",count) Console.ReadLine() End Sub End Module
效果:
原文链接:/vb/259506.html