一百元钱,小鸡 0.5元,公鸡3元,母鸡4元,每一种鸡都买,各能买多少只?
一百元钱,小鸡 0.5元,公鸡3元,母鸡4元,每一种鸡都买,各能买多少只?JAVA编写!
public class CNumber{
public static void main(String[] args){
int rooster; //公鸡
int hen; //母鸡
int chicken; //小鸡
for(rooster = 0; rooster < 50; rooster++){
for(hen = 0; hen < 50; hen++){
chicken = 100-rooster-hen;
if(rooster*3 + hen*4 + chicken * 0.5 == 100 && rooster + hen + chicken == 100){
System.out.println("公鸡" + rooster + "只" + "母鸡" + hen + "只" + "小鸡" + chicken + "只");
}
}
}
}
}