百钱买百鸡,5文钱一只公鸡,4文钱一只母鸡,1文钱可以买3只小鸡,要求用100文钱买100只鸡: public static void main (String []args) { for(int a=0;a<=20;a++){ for (int b = 0; b<=25; b++){ int c = 100 - a - b; if (a * 5 + b * 4 + c / 3 ==100 && c%3==0){ System.out.print("a:"+a); System.out.print("b:"+b); System.out.print("c:"+c); } } } }
计算四位整数abcd中满足 (ab+cd)(ab+cd)=abcd 的数:
public static void main (String []args) { for (int abcd = 1000; abcd <= 9999; abcd++) { int ab = abcd / 100; int cd = abcd % 100; if ((ab + cd) * (ab + cd) == abcd) { System.out.print(abcd); } }
}
计算水仙花数。水仙花是指一个三位数abc